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 ?):

\usepackage{lmodern} % with or without this...

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


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}.

  • You should rather teach Pandoc to use \url (package url or hyperref) instead of \texttt for URLs.
    – egreg
    Oct 23, 2014 at 14:48
  • possible duplicate of How to automatically hyphenate within \texttt? Oct 23, 2014 at 14:51
  • @PeterGrill thanks, indeed I didn't find that question before. However, I tried it with no effect (see my edited question). I must be missing something...
    – mb21
    Oct 23, 2014 at 15:38
  • Pandoc can use fancyvrb and also lets you specify your own TeX template (#14 at Pandoc - Demos, so I'm not sure why it's using \texttt for inline code anyway. Oct 23, 2014 at 15:50
  • @MikeRenfro I'm guessing it's using fancyvrb only for special situations, and templates don't affect the stuff that it puts where the $body$ variable is.
    – mb21
    Oct 23, 2014 at 17:05

1 Answer 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, 2014 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.