4

According to p. 881 of the TikZ & PGF manual for version 3.0.1a, the following LaTeX manuscript:

\documentclass{article}
\usepackage{pgfkeys}
\begin{document}
    \pgfkeysdefargs{/my key}{#1+#2}{\def\a{#1}\def\b{#2}}
    \pgfkeys{/my key=hello+world}
    |\a| is \a, |\b| is \b.
\end{document}

should typeset as follows (sans background color):

Expected output: with backslashes

In other words, it appears the vertical bars serve as verbatim. (This is not the first time that I come across this usage. So far I've ignored it whenever I came across it, but I feel now's a good time to get to the bottom of it.)

However, when I compile this manuscript with pdflatex, the body of the resulting PDF document looks like this:

Actual output: with long dashes

Why aren't the vertical bars recognized as verbatim markers? And why do they show up as dashes?


This is not a duplicate of this question. This is not about the font but about the fact that the vertical bar is not interpreted as verbatim.

Evan Aad
  • 11,066

1 Answers1

6

The LaTeX kernel does not attach any special meaning to |, so you will need to do so. Probably this is easiest using fancyvrb

\documentclass{article}
\usepackage{pgfkeys}
\usepackage{fancyvrb}
\DefineShortVerb{\|}
\begin{document}
    \pgfkeysdefargs{/my key}{#1+#2}{\def\a{#1}\def\b{#2}}
    \pgfkeys{/my key=hello+world}
    |\a| is \a, |\b| is \b.
\end{document}

In PGF manual, the vertical bar is prepared similarly in pgfmanual-en-macros.tex

{
  \catcode`\|=12
  \gdef\pgfmanualnormalbar{|}
  \catcode`\|=13
  \AtBeginDocument{\gdef|{\ifmmode\pgfmanualnormalbar\else\expandafter\verb\expandafter|\fi}}
}
percusse
  • 157,807
Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036