2

I recently noticed a subtle issue while working on a paper: with savetrees enabled, when you use \tt inside running text, LaTeX switches to the monospace font before inserting the interword space, but then when it returns to the prevailing font it uses that font's interword space. If you use \texttt instead, the space both before and after the monospace text are set in the monospace font.

Here's a minimal example:

\documentclass{article}

\usepackage[subtle]{savetrees}

\begin{document}

You should use the {\tt mkdir} command to create directories.

You should use the \texttt{mkdir} command to create directories.

\end{document}

This produces:

sample of inconsistent spacing

The spacing difference after "mkdir" is obvious. If you look more carefully, you'll note that on both lines the space before "mkdir" is also wider than the space between other words (e.g. in "use the").

Commenting out savetrees makes the problem go away; the spacing around "mkdir" becomes the same as the spacing between other words regardless of which typesetting approach is used.

I experimented and found that I could use \hspace{0pt} in front of the {\tt mkdir} to cause savetrees to use the prevailing font's whitespace settings. (Actually I'm using \hspace{0pt}\nolinebreak because it's all inside a macro.) But that seems like an ugly hack. I tried {} as a cleaner option but it had no effect.

So: (1) is this a savetrees bug? and (2) is there a better way to work around it? I want the prevailing font's whitespace on both sides of "mkdir", since to my eyes it looks better and anyway the spaces aren't inside the changed font.

6
  • When compiled with lualatex they look the same.
    – rallg
    Sep 21 at 20:47
  • 3
    \tt should not be used anyway (it is not defined by default in latex, article just defines it for compatibility with latex2.09 documents from the 19980s) Sep 21 at 21:21
  • 1
    {\ttfamily mkdir} gives same space as ` \texttt{mkdir} ` Sep 21 at 21:23
  • Welcome! Since savetrees isn't, to my understanding, intended for typesetting the final version, I'm not sure how concerned you should be about less appealing spacing in this kind of case, but it does seem odd that a package designed to save trees should use more paper.
    – cfr
    Sep 22 at 0:26
  • @rallg The underlying issue is present with LuaLaTeX, too. The reason it doesn't show up is because savetrees only enables the relevant option for pdfLaTeX, since it wasn't supported in LuaLaTeX at the time.
    – cfr
    Sep 23 at 5:06

1 Answer 1

1

This is not a solution, but an explanation with one not-very-satisfactory workaround and a second hideous one.

The basic problem is not in savetrees but microtype. Initially, I assumed it must have to do with word spacing, but drew a blank. The problem is actually triggered by tracking. So one workaround is to use savetrees but disable this particular option.

To see the problem, you can trace tracking through savetrees's quite simple code in the documentation. The option is implemented using microtype, but only if we're producing PDF and LuaTeX is not the engine.

The following is equivalent to loading savetrees with subtle and only tracking enabled.

\documentclass{article}

\usepackage[letterspace=-25]{microtype}
\newcommand \sttest{%
  You should use the {\tt mkdir} command to create directories and not use {\tt\textbackslash tt}!\par
  You should use the {\ttfamily mkdir} command to create directories and not use {\ttfamily\textbackslash tt}!\par
  You should use the \texttt{mkdir} command to create directories and not use \texttt{\textbackslash tt}!\par
  You should use the \texttt{mkdir}{} command to create directories and not use \texttt{\textbackslash tt}!\par
}

\begin{document}
\sttest


{\lsstyle
  \sttest}
\SetTracking[
  spacing={-25*,,},
  outer spacing={-25*,,},
  outer kerning={0,0},
]{encoding=*}{-25}
{\lsstyle
  \sttest}

\end{document}

microtype-only emulation of savetrees's tracking option with subtle settings

Workaround 1

Use savetrees with all options except tracking.

\documentclass{article}

\usepackage[subtle,tracking=normal]{savetrees}%,tracking=tight
\usepackage{microtype}
\newcommand \sttest{%
  You should use the {\tt mkdir} command to create directories and not use {\tt\textbackslash tt}!\par
  You should use the {\ttfamily mkdir} command to create directories and not use {\ttfamily\textbackslash tt}!\par
  You should use the \texttt{mkdir} command to create directories and not use \texttt{\textbackslash tt}!\par
  You should use the \texttt{mkdir}{} command to create directories and not use \texttt{\textbackslash tt}!\par
}

\begin{document}
\parindent=0pt
\sttest


{\lsstyle
  \sttest}
\end{document}

Obviously, if you then use letterspacing, you'll get a bizarre result, but presumably you could omit \lsstyle in your real document. (It is not recommended for general usage, but only for caps/small-caps and in specialist cases.) This will use a little more paper (but be typographically superior, of course). savetrees without tracking and default microtype

Workaround 2

If you are really committed to reducing paper, you could enable savetrees's tracking locally. I absolutely wouldn't do this (but I don't use savetrees either). If you nonetheless wish to do so, you can set microtype up so that letter-spacing emulates savetrees's tracking option and use \lsstyle to enable it locally.

\documentclass{article}

\usepackage[subtle,tracking=normal]{savetrees}
\makeatletter
\usepackage[letterspace=\st@cspace@shrink]{microtype}
\makeatother
\newcommand \sttest{%
  You should use the {\tt mkdir} command to create directories and not use {\tt\textbackslash tt}!\par
  You should use the {\ttfamily mkdir} command to create directories and not use {\ttfamily\textbackslash tt}!\par
  You should use the \texttt{mkdir} command to create directories and not use \texttt{\textbackslash tt}!\par
  You should use the \texttt{mkdir}{} command to create directories and not use \texttt{\textbackslash tt}!\par
}

\begin{document}
\parindent=0pt
\sttest

{\lsstyle
  \sttest}
\end{document}

A strongly disrecommended workaround with local use of savetrees tracking

But if you're OK with that, I doubt you'd have asked the original question .... So workaround 1 is likely preferable.

4
  • Thanks for the extremely detailed analysis, cfr. I'll try to learn more about the tracking option and horizontal spacing in general. I'll add only that FWIW, savetrees is quite commonly used in paper submissions to venues that have a page limit. In a 12-page paper, even the subtle setting can be worth a quarter of a page or so, without significant harm to readability. So yeah, this actually is a (near-)final version.
    – gkuenning
    Sep 23 at 6:42
  • @gkuenning Ah, are you in the US? Though even in the US, professional venues tend to give word limits in my discipline. It was only students who were given limits in pages, which always struck me as quite bizarre. Here it is always words. Even at GCSE, we had word limits (exams at 16). In one case, we even had word limits on exam answers. (I thought that was bonkers, too.)
    – cfr
    Sep 23 at 7:09
  • In my field it has always been page limits, because those translate directly to publication costs. Although that's not terribly relevant nowadays, but history...
    – gkuenning
    Sep 26 at 0:17
  • Interesting. In my field, the author's page count would hardly ever be an indication of the published page count (historically or currently). It's very rare for authors to be asked for typeset content. They always take it and set it themselves (with one or two notable as exceptions, but they're newer and electronic only).
    – cfr
    Sep 26 at 0:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .