6

I am trying to generate PDF documentation out of Pandoc Markdown README document. Here is MWE:

\documentclass[english,]{article}
\usepackage[T1]{fontenc}
\usepackage{ifxetex,ifluatex}

\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[utf8]{inputenc}
\else % if luatex or xelatex
  \ifxetex
    \usepackage{mathspec}
    \usepackage{xltxtra,xunicode}
  \else
    \usepackage{fontspec}
  \fi
\fi

\defaultfontfeatures{Ligatures=TeX}
\setmonofont[Scale=MatchLowercase]{DejaVu Sans Mono}

\begin{document}
\texttt{-{}-enable-debugging}
\end{document}

When I generate a PDF using lualatex (beta-0.76.0-2013070111 (TeX Live 2013/Debian) (rev 4627)) it creates a en-dash instead of typesetting --:

unwanted en-dash picture

The en-dash is unwanted. XeLaTeX does not do that. I want two dashes.

UPDATE

In the end, I have created a patch that makes Pandoc use -\/- instead of -{}- to avoid the ligature.

wilx
  • 2,339
  • 1
    Don't use \defaultfontfeatures{Ligatures=TeX} before declaring the mono font. – egreg Feb 06 '14 at 22:34
  • 2
    Note also that inserting {}, i.e., an "empty TeX group", does not work as a ligature-suppressing method under Lua(La)TeX, though it does so under Xe(La)TeX and pdf(La)TeX. – Mico Feb 06 '14 at 22:40
  • 2
    So how would you break a single ligature in Lua(La)TeX? That is, if you want ligatures generally but need -- or ff without ligaturing in a particular case? – cfr Feb 06 '14 at 23:10
  • @cfr - Under LuaLaTeX, I would suggest loading the selnolig package. Specify either the english or ngerman option to load language-specific selective ligature suppression rules, or provide your own homemade ligature suppression rules -- say, \nolig{--}{-|-} -- to suppress certain ligatures on a document-wide basis. To suppress a single instance of a ligature, one could issue the command \breaklig, e.g., \breaklig{pdf|latex}. – Mico Feb 06 '14 at 23:28
  • @Mico Interesting. So there's a solution for English and German but maybe not for other languages. (I don't know if it is an issue in other languages, though. To be honest, I'm not sure of the rules even for English and certainly never use them!) – cfr Feb 06 '14 at 23:39
  • @cfr - Fortunately there aren't that many ligature-suppressing rules in English to begin with. :-) (The rule \nolig{lfful}{lf|ful} takes care of words such as "shelfful", which is mentioned in the TeXbook...) The situation is quite different with German -- the selnolig package features roughly twenty [20!] times as many \nolig rules for ngerman as it does for english. – Mico Feb 06 '14 at 23:56
  • I don't find that at all surprising ;). – cfr Feb 07 '14 at 00:00

1 Answers1

5

The error is in declaring

\defaultfontfeatures{Ligatures=TeX}

before loading the mono font. This will add the common TeX ligatures to the normal set, in particular turns -- into an en-dash.


By the way, you shouldn't load either xltxtra or xunicode; xltxtra has some features, but it's quite improbable you really need them. It used to be recommended when fontspec was in its older versions. Now it does the main things xltxtra was used for and also loads xunicode. Since mathspec loads fontspec just that package is sufficient.

Also avoid fontenc for XeLaTeX and LuaLaTeX. Put it in the pdflatex specific part.

Mico
  • 506,678
egreg
  • 1,121,712
  • This MWE is derived from Pandoc generated LaTeX document. It adds those bits of its own. – wilx Feb 06 '14 at 23:14
  • 2
    @wilx Not the best code, to tell you the truth. Besides, thinking that the same document can be processed with the three engines using that preamble is just a dream: you can't emulate mathspec with LuaTeX and you can't use a document using specific mathspec features with pdflatex. – egreg Feb 06 '14 at 23:24
  • Pandoc's conversion is best effort. Feel free to improve Pandoc's LaTeX template. – wilx Feb 06 '14 at 23:44