# Size/density of dots used by \dotuline command (ulem package)

I would like to use the \dotuline command (from the ulem package) to create a "fill in the blanks" document.

It gives good results but when the blank becomes small it is hardly noticeable (a single dot in the following MWE):

\documentclass[a4paper,11pt]{article}
\usepackage{ulem}

\begin{document}
A sentence with a ....... to fill.
A sentence with a \dotuline{~~~~~~~} to fill.

A small ... to fill.
A small \dotuline{~~} to fill.
\end{document}


Is there a way to control the size and/or the density of the dots of this command?

Taking the definition of \dotuline from ulem.sty:

\def\dotuline{\bgroup
\UL@setULdepth
\markoverwith{\begingroup
\lower\ULdepth\hbox{\kern.1em .\kern.04em}%
\endgroup}%
\ULon}


one can see that the part responsible for the actual dots is \hbox{\kern.1em .\kern.04em}. So it's quite easy to change these values or to create a macro that takes the spacing as argument. For example:

\documentclass[a4paper,11pt]{article}
\usepackage{ulem}

\usepackage{graphicx}

\makeatletter
\def\NewDotuline#1{\bgroup
\UL@setULdepth
\markoverwith{\begingroup
\lower\ULdepth\hbox{.\kern#1}%
\endgroup}%
\ULon}

\def\SmallDotuline#1{\bgroup
\UL@setULdepth
\markoverwith{\begingroup
\lower\ULdepth\hbox{\scalebox{0.7}{.}\kern#1}%
\endgroup}%
\ULon}
\makeatother

\begin{document}
\pagenumbering{gobble}
A sentence with a ....... to fill.
A sentence with a \dotuline{~~~~~~~} to fill.

A small ... to fill.
A small \dotuline{~~} to fill.

A sentence with a ....... to fill.
A sentence with a \NewDotuline{0em}{~~~~~~~} to fill.

A small ... to fill.
A small \NewDotuline{0em}{~~} to fill.

A sentence with a ....... to fill.
A sentence with a \NewDotuline{-0.1em}{~~~~~~~} to fill.

A small ... to fill.
A small \NewDotuline{-0.1em}{~~} to fill.

A sentence with a ....... to fill.
A sentence with a \SmallDotuline{-0.05em}{~~~~~~~} to fill.

A small ... to fill.
A small \SmallDotuline{-0.05em}{~~} to fill.
\end{document}

• As you provide two different answers, I suggest you split your post. It would be easier to read. – Tobard Sep 15 '18 at 14:54
• @Tobard If you insist :) – Phelype Oleinik Sep 15 '18 at 18:40

Just for the fun of it: a keyval interface to a configurable version of \dotuline.

The command is now called \ULine and you can modify:

• What is printed with the text key. For example, you can use text={\tikz[scale=0.05]\duck;} :D
• The kern inserted before and after the text with pre and pos
• The depth of the underline with depth (you can tweak the depth to make an overline -- I did it with -2ex in the example with text={,})

The values can be changed locally with the optional argument to \ULine or globally with \SetULine.

Result:

Code:

\documentclass[a4paper,11pt]{article}
\usepackage{ulem}
\usepackage{graphicx}
\usepackage{xparse}
\usepackage{tikzducks}
\usepackage{tikzmarmots}

\ExplSyntaxOn
\keys_define:nn { uline } {
,text   .code:n       = \cs_set:Nn \uline_text: { #1 }
,pre    .dim_set:N    = \l_uline_kern_pre
,pre    .initial:n    = 0.1em
,pos    .dim_set:N    = \l_uline_kern_pos
,pos    .initial:n    = 0.04em
,depth  .dim_set:N    = \l_uline_depth
,depth  .initial:n    = 0.08ex
}
\NewDocumentCommand{\SetULine}{ m }
{ \keys_set:nn { uline } { #1 } }
\cs_new:Npn \uline_text: { . }
\NewDocumentCommand\ULine
{ o }
{
\c_group_begin_token
\IfValueT { #1 }
{ \keys_set:nn { uline } { #1 } }
\use:c { UL@setULdepth }
\markoverwith
{
\group_begin:
\box_move_down:nn { \ULdepth }
{
\hbox:n {
\tex_kern:D \l_uline_kern_pre \scan_stop:
\uline_text:
\tex_kern:D \l_uline_kern_pos \scan_stop:
}
}
\group_end:
}
\ULon
}
\ExplSyntaxOff

\begin{document}
\pagenumbering{gobble}

A sentence with a ........ to fill.

A sentence with a \ULine[pre=0pt,pos=0pt]{~~~~~~~} to fill.

A sentence with a \ULine[pre=0pt,pos=-0.1em]{~~~~~~~} to fill.

A sentence with a \ULine[text=\scalebox{0.7}{.},pre=0pt,pos=-0.05em]{~~~~~~~} to fill.

A sentence with a \ULine[depth=-2ex,text={,}]{~~~~~~~} to fill.

A sentence with a \ULine[text={\tikz[scale=0.05]\duck;},pre=-0.05em]{~~~~~~~} to fill.

A sentence with a \ULine[text={\tikz[scale=0.15]\marmot;},pre=-0.05em,depth=1ex]{~~~~~~~} to fill.

\end{document}