# Break on special characters in inline verbatim

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}  • You should rather teach Pandoc to use \url (package url or hyperref) instead of \texttt for URLs. – egreg Oct 23 '14 at 14:48 • possible duplicate of How to automatically hyphenate within \texttt? – Peter Grill Oct 23 '14 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 '14 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. – Mike Renfro Oct 23 '14 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 '14 at 17:05

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.
• replace \texttt with \mytexttt
• or drop lmodern and use \usepackage[T1]{fontenc}
• or drop lmodern and use \DeclareFontFamily{OT1}{cmtt}{\hyphenchar \font=63}