share
TeX - LaTeXWriting practice sheets - dotted letters
[+35] [1] Simd
[2013-02-04 19:30:07]
[ fonts ]
[ https://tex.stackexchange.com/questions/96766/writing-practice-sheets-dotted-letters ]

I would like to make writing practice sheets similar to the following.

How can you make "dotted" fonts like this?

The closest I saw on this forum was How can I convert text to paths with pdflatex? [1] but I don't know if \pscharpath can be modified/used to do this job. Or maybe there is a TikZ solution?

Update. My plan was to position the horizontal lines using trial and error. Is there, alternatively, some way to get the correct height of a lower case and upper case letter automatically?

(1) I doubt that any automatic procedure will produce satisfactory results. Maybe you can find some existing dotted fonts in opentype format and use them with Xelatex? - Michael Palmer
A rather crude (albeit effective) method would be to superimpose some kind of grid made of white lines?... Or to do the whole thing with TikZ perhaps? - Count Zero
(4) As a basis, you’re gonna need a font that looks like handwriting is supposed to – unless you want kids (assuming that’s the target group) to learn how to write in Compute Modern. I think there are some packages for such fonts though, and with Xe/LuaTeX, you can use any font, of course. - doncherry
(1) @doncherry I found fontspace.com/kids-fonts/trace which is not terrible and works in Xelatex. You make a very good point about whether it is sufficiently like handwriting. It's not really designed for this purpose though as, for example, the spacing is proportional which isn't ideal for a writing practice sheet with different letters on it. - Simd
If you have an OpenType version of your font you can try generating an outline version of your font with otftotfm. Before doing this, make sure your font licence agreement allows it. How to get a dotted version, I don't know. - user10274
[+24] [2013-02-06 21:04:10] Scott H. [ACCEPTED]

Here's something that seems similar to what you're after. The macro is:

\setline{<scale factor>}{<text>}

The height of scaled upper and lower case x's in the document font are measured to draw the lines. The dotted effect comes from \pdfliteral{q 1 Tr [1 4]0 d}#2\pdfliteral{Q} where:


The pdf commands are documented in Chapter 4 of the PDF Reference [1]

  • q saves the graphic state
  • 1 Tr traces the outline of the glyph rather than filling it
  • [1 4]0 d sets the stroke style to (pretty much) dashed 1 on 4 off starting with a dash.
  • Q means restore the graphics state to what it was

Edit: Apparently the settings above are somewhat viewer dependent. The given settings with Sumatra, give the output pictured below. To get the "same" output with Adobe Reader (at least my version) Change the line given above to:

\pdfliteral{q 1 Tr [.1 .4]0 d .1 w}#2\pdfliteral{Q}

I tried it with a bunch of fonts from The LaTeX Font Catalogue [2] and while most worked, some didn't (in particular Calligra...not sure why). As mentioned in the comments, if you could find a suitable font then this might work for you. A couple examples of output below: enter image description here enter image description here

\documentclass{article}
\usepackage{graphicx}
\usepackage{dashrule}

\newsavebox\myboxX
\newsavebox\myboxx
\newdimen\heightX
\newdimen\heightx

\newcommand{\setline}[2]{%
    \savebox\myboxX{\scalebox{#1}{X}}%
    \savebox\myboxx{\scalebox{#1}{x}}%
    \heightX=\ht\myboxX
    \heightx=\ht\myboxx
    \noindent\ooalign{\rule[\heightX]{\textwidth}{.1pt}\cr
    \noindent\hdashrule[\heightx]{\textwidth}{.1pt}{1mm}\cr
    \noindent\rule{\textwidth}{.1pt}\cr
    \noindent\scalebox{#1}{#2}\scalebox{#1}{\pdfliteral{q 1 Tr [1 4]0 d}#2\pdfliteral{Q}}}%
    % For Adove, use this setting rather than the one above.
    %\noindent\scalebox{#1}{#2}\scalebox{#1}{\pdfliteral{q 1 Tr [.1 .4]0 d .1 w}#2\pdfliteral{Q}}}%
}

\begin{document}

\setline{5}{Abc}\vspace{1cm}
\setline{5}{De}\vspace{1cm}

\end{document}
[1] http://partners.adobe.com/public/developer/en/pdf/PDFReference.pdf
[2] http://www.tug.dk/FontCatalogue/

(2) Is there something special required to run this. I am not quite getting the results that you are: What I get is this image. - Peter Grill
Hmmm, I don't think so...I just compiled with latex->pdf. I'll check after class to see if I can figure out what might be failing. - Scott H.
@petergrill I did delete a font command before posting, but I believe it worked with the default font as well. - Scott H.
Ok, I'll ask in chat to see if it your solutions works for others. - Peter Grill
(1) It seems that Nicola Talbot, Silex and tohecz gets the same results as I do -- Also I get identical results with TeXLive 2010, 2011 and 2012, so not sure how it worked for you. - Peter Grill
(1) @ScottH. If I change [1 4] to [.1 .4] the result looks a bit better, so I suspect that it is a problem of setting some "base unit": i.sstatic.net/pvWf5.png - yo'
@PeterGrill With Adobe Reader, I get the same output as you do, with Sumatra I get what I posted. Presumably, Adobe is correct, but I wonder why Sumatra is giving what I expect as output. - Scott H.
(2) I think @tohecz is on to the source of the problem. Sumatra must have a different "base unit". But I know nothing about this to be able to help you -- it looked interesting so that is why I started to try your example. - Peter Grill
@ScottH. Works for me, with Adobe Reader. Great answer. - yannisl
@YiannisLazarides: Even with Acrobat 10.1.5 (on both Mac 10.6.8 and Windows 7) I do not get the correct output. Which version of Acrobat are you using? - Peter Grill
@petergrill In the edit, I added an alternate string that seems to give better results with acrobat. Does it still give poor results even with that? - Scott H.
@ScottH.: Yes, uncommenting the other setting works fine in TeXWorks viewer and Acrobat. - Peter Grill
@PeterGrill version 8.3.2 and also runs with TeXworks which uses the Poppler library. - yannisl
Nice solution. The commented line works much better for me (evince) than the other, which doesn't seem to work at all. - user10274
Thanks for the answer, it has helped me! I have a related problem: I'm using your bare pdfliteral commands to typeset dotted outlines of words. But the normal text that goes afterwards is misplaced. Do you have perhaps an idea how to overcome this? I have a multiline dotted text. - imz -- Ivan Zakharyaschev
I've solved the problem with mispositioned text afterwards by adding page keyword to pdfliteral, as shown at permalink.gmane.org/gmane.comp.tex.pdftex/4392 - imz -- Ivan Zakharyaschev
1