5

I would like to always get vertical quotes for ' and " when using the tt font. I can get that with the upquote package for verbatim environments, and with the macros provided by textcomp, but I would also like it to be the default for \texttt and \ttfamily.

\documentclass{article}
\usepackage{textcomp, upquote}
\begin{document}
\verb|This is a vertical quote: '|

\texttt{I wish this were a vertical quote: '
(like this one: \textquotesingle)}
\end{document}

Is there a way to do that? And let me add, with pdflatex, before someone suggests some remapping command that only works with xelatex/lualatex.

Edit: I have succeeded in implementing a solution via Heiko Oberdiek's lm-ec-tt.map method, at least via the \pdfmapfile command. (I have not yet tried to put the modified .map and .enc files in my ~/texmf area.)

But I also succeeded in getting \ttfamily redefined, which is a path I think I'd prefer. Unfortunately, \texttt still doesn't work. In my (obviously wrong) understanding of the code in article.cls, \texttt should be defined in terms of \ttfamily. So why doesn't the following work for \texttt?:

\documentclass{article}
\usepackage{textcomp, upquote}

\makeatletter
\renewcommand\ttfamily
        {\not@math@alphabet\ttfamily\mathtt
         \fontfamily\ttdefault\selectfont
         \@noligs}% all I do is add this
\makeatother

\begin{document}
\texttt{texttt: quote:'; doublequote:"; grave:`}\par      % doesn't work
{\ttfamily ttfamily: quote:'; doublequote:"; grave:`}\par % works
\verb| verb: quote:'; doublequote:"; grave:`|\par
\end{document}
dedded
  • 2,236
  • @barbarabeeton: No, that answer uses upquote, which only affects \verb and verbatim. I know about that (see my MRE). I'm looking for a way to get \texttt to do the same thing. – dedded Jan 16 '17 at 16:16
  • another possibility: Typewriter quotation marks in texttt. it only covers the double quote/ditto, but the same mechanism can be used for the single quote (although i can't think of a good short name for it). – barbara beeton Jan 16 '17 at 18:03
  • @barbarabeeton, thanks for your persistence, but that's not what I'm asking either. I can get a vertical quote in \texttt with \textquotesingle/dbl; what I want is for the characters ' and " to be interpreted as vertical quotes within \texttt. – dedded Jan 16 '17 at 18:09
  • Why don't you just define a new environment or macro to replace \ttfamily or whatever? Note that you certainly can get this to work in pdfTeX because you can always define a new font and use that for typewriter text. But you probably don't want to go to that much trouble. – cfr Jan 17 '17 at 01:41
  • @cfr, that sounds promising, but I'm missing something. See my attempt in the edited question. – dedded Jan 17 '17 at 12:20

1 Answers1

3

LuaTeX

If LuaTeX or XeTeX is an option, then the default font of package fontspec uses the Latin Modern fonts (the successors of the Computer Modern fonts). There, the single and double quote are plain vertical:

\documentclass{article}
\usepackage{fontspec}
\begin{document}
\verb|These are vertical quotes: ' and "|

\texttt{These are vertical quotes: ' and "}

\texttt{These are vertical quotes: \textquotesingle\ and \textquotedbl}
\end{document}

Result

XeTeX

XeTeX also work, but the spacing is different, because it respects the space factor settings better that are active in \texttt in opposite to \verb that automatically sets \frenchspacing.

Result XeTeX

pdfTeX

A clean solution for pdfTeX would be to change the encoding of the typewriter font to replace the single quote. The map file entries look like:

ec-lmtt10 LMMono10-Regular " enclmec ReEncodeFont " <lm-ec.enc <lmtt10.pfb

The encoding is defined in file lm-ec.enc. It can be located via:

kpsewhich lm-ec.enc

This file can be copied to lm-ec-tt.enc, which replaces /quotesingleright by /quotesingle:

...
/ampersand
/quotesingle
/parenleft
...

Then a map file lm-ec-tt.map for the affected fonts can be created that uses the new encoding file lm-ec-tt.enc:

ec-lmtt10 LMMono10-Regular " enclmec ReEncodeFont " <lm-ec-tt.enc <lmtt10.pfb
ec-lmtt12 LMMono12-Regular " enclmec ReEncodeFont " <lm-ec-tt.enc <lmtt12.pfb
ec-lmtt8 LMMono8-Regular " enclmec ReEncodeFont " <lm-ec-tt.enc <lmtt8.pfb
ec-lmtt9 LMMono9-Regular " enclmec ReEncodeFont " <lm-ec-tt.enc <lmtt9.pfb
ec-lmtti10 LMMono10-Italic " enclmec ReEncodeFont " <lm-ec-tt.enc <lmtti10.pfb
ec-lmtto10 LMMonoSlant10-Regular " enclmec ReEncodeFont " <lm-ec-tt.enc <lmtto10.pfb
ec-lmvtk10 LMMonoPropLt10-Bold " enclmec ReEncodeFont " <lm-ec-tt.enc <lmvtk10.pfb
ec-lmvtko10 LMMonoPropLt10-BoldOblique " enclmec ReEncodeFont " <lm-ec-tt.enc <lmvtko10.pfb
ec-lmvtl10 LMMonoPropLt10-Regular " enclmec ReEncodeFont " <lm-ec-tt.enc <lmvtl10.pfb
ec-lmvtlo10 LMMonoPropLt10-Oblique " enclmec ReEncodeFont " <lm-ec-tt.enc <lmvtlo10.pfb
ec-lmvtt10 LMMonoProp10-Regular " enclmec ReEncodeFont " <lm-ec-tt.enc <lmvtt10.pfb
ec-lmvtto10 LMMonoProp10-Oblique " enclmec ReEncodeFont " <lm-ec-tt.enc <lmvtto10.pfb

Then the pdfTeX document starts at the very beginning with the replacement of these fonts: \pdfmapfile{=lm-ec-tt.map}

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{textcomp}
\begin{document}
\verb|These are vertical quotes: ' and "|

\texttt{These are vertical quotes: ' and "}

\texttt{These are vertical quotes: \textquotesingle\ and \textquotedbl}
\end{document}

Result pdfTeX

The trick via the map and encoding file works for this case, because the bounding boxes of the symbols that are exchanged are the same.

Heiko Oberdiek
  • 271,626
  • I'm using pdflatex, so I'll try to digest what you said about mapping tonight. Is there an area in my ~/.texmf directory where I can drop a new map file and have it be used automatically? (And would that be a bad idea for some reason?) Also, I'm using zlmtt, not lmodern, since I'm usually using some other roman font (libertine or XCharter, usually). I'll assume that zlmtt should still work, since it's supposed to be the latin modern tt font. – dedded Jan 17 '17 at 19:13
  • @dedded Usually, the local or home tree (kpsewhich -expand-var '$TEXMFLOCAL' or kpsewhich -expand-var '$TEXMFHOME' are the roots, where the user can add the files. Just use the same directory hierarchy as the original files. The local texmf tree also nees a run of texhash (or mktexlsr). – Heiko Oberdiek Jan 17 '17 at 19:32
  • @dedded The method of the answer can also work for other fonts if the straight glyph versions are contained in the Type 1 font. The map entries needs to be identified (pdftex.map). If an encoding file is given, then it needs to be modified, see the answer. The glyph positions and names can be reviewed by a font editor, e.g. fontforge. – Heiko Oberdiek Jan 17 '17 at 19:37
  • I got this to work (so far just with \pdfmapfile), thank you very much. You mentioned needing to run texhash or mktexlsr if I were to put these files in my texmf tree. In this link (https://tex.stackexchange.com/q/255709/), @cfr recommends against running updmap. Will there be similar issues with texhash or mktexlsr? Following a different path, I also succeeded in redefining \ttfamily without making a new .map file. If I can only get \texttt working, that technique is promising. See the original question that I just edited. – dedded Jan 19 '17 at 13:02
  • @dedded texhash/mktexlsr is not the same as updmap. The former commands just updates the ls-R file at the root of the texmf tree. Usually the TeX programs (more precise, programs that use the kpathsea library) do a fast lookup via ls-R for the system and local texmf trees to find a file and they do not search the file system tree (slow operation). – Heiko Oberdiek Jan 19 '17 at 19:07
  • So I wouldn't need to remember to re-run texhash when I update texlive? – dedded Jan 19 '17 at 19:11
  • @dedded "update texlive" can be anything. If files are added/deleted from a texmftree, then ls-Rshould be regenerated. I assume tlmgr does this automatically. But if files are added/deleted manually, then texhash needs to be run for the tree. – Heiko Oberdiek Jan 19 '17 at 19:22
  • I find that I cannot use this answer, because in the end it's not really practical to customize the Latex environment at work; and there's no sense in customizing a personal environment in this way when some documents are developed collaboratively. But I feel like I have learned a great deal from it and that I have a better handle on how at least some aspects of fonts work in Latex than I ever had. – dedded Jan 23 '17 at 12:47