[Tex/LaTex] Writing practice sheets – dotted letters

fonts

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? 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?

Best Answer

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

  • 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 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}