2

I'm using Pandoc to generate LaTeX. My text contains inline code spans (backticks in markdown) that are rendered as \texttt{...} in TeX. However, some of them are quite long and overflow the line, for example this paragraph:

In the context of the variables
\texttt{\{"query": "mycelium", "number": 100\}}, this would be expanded to
the URI \texttt{http://www.example.com/foo?query=mycelium\&number=100}.

I cannot change the generated code since that would affect the output when rendering to HTML.

I tried to insert a unicode zero-width space, but pdflatex chokes on that. I cannot use TeX commands inside the verbatim environment since Pandoc escapes all those before outputting them inside a \texttt:

$ echo 'my `code\bar`' | pandoc -t latex
my \texttt{code\textbackslash{}bar}

So what I'm looking for is a TeX command that redefines \texttt to reflow the line when it's too long. Or alternatively, a command to break all words that are too long on special characters like ?=%&.

Edit: I tried the following but it doesn't have any effect (63 being the decimal ascii code point for ?):

\documentclass[]{article}
\usepackage{lmodern} % with or without this...

% ... either of the following don't work:
\DeclareFontFamily{T1}{cmtt}{\hyphenchar \font=63}
\DeclareTextFontCommand{\mytexttt}{\ttfamily\hyphenchar\font=63\relax}

\begin{document}

In the context of the variables
\texttt{\{"query": "mycelium", "number": 100\}}, this would be expanded to
the very long long long URI \texttt{http://www.example.com/foo?query=mycelium\&number=100}.

\end{document}
mb21
  • 790
  • 4
  • 19

1 Answers1

1

Your example can't break at the ? because the first definition defines the hyphenchar for cmtt in T1 encoding (and you use lmodern) and the second defines \mytexttt but your document uses \texttt.

If you

  • replace \texttt with \mytexttt
  • or drop lmodern and use \usepackage[T1]{fontenc}
  • or drop lmodern and use \DeclareFontFamily{OT1}{cmtt}{\hyphenchar \font=63}

then your example works for me (albeit with an overfull box as the ? comes too late.

  • Thanks a lot! You're completely right. I guess I was almost there when I despaired :) – mb21 Oct 28 '14 at 15:35