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}
\url
(packageurl
orhyperref
) instead of\texttt
for URLs.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.fancyvrb
only for special situations, and templates don't affect the stuff that it puts where the$body$
variable is.