Objective
I'm trying to achieve the following output.
Here's the code I used to produce it. I had to hack it
\begin{document}
\begin{description}
\item In \texttt{./build/org.eclipse.cdt.managedbuilder.core/plugin.xml}
\\ there is an extension
{\btHL \texttt{org.eclipse.cdt.managedbuilder.language} }
{ \btHL \texttt{.settings.providers.GCCBuildCommandParser}}
corresponding to the name \texttt {GCCBuildOutputParser.name}.
This is extending at the point
{\btHL \texttt{org.eclipse.cdt.core.LanguageSettingsProvider}}
\end{description}
\end{document}
As you can see, I had to manually insert line breaks to typeset it correctly. I'd like to have LaTeX automatically break the lines also.
The preamble that defines \btHL
was taken from Highlight text in code listing while also keeping syntax highlighting
Why?
As I've shown in the example above, java classes can be really long string with no spaces. And sometimes you need to mention them inline. On top of that I think highlighting them(adding background color) will enhance the readability. As it's java code I want to typeset it in monospace. Syntax highlighting is not a high priority though.
The Challenge
So far I've looked at the following answers for wrapping text
- Wrapping long lines that contain no spaces
- http://mrtextminer.wordpress.com/2009/02/26/break-or-wrap-a-continuous-text-in-latex/
- Long code that needs to wrap
- How to make inline listings wrap nicely?
- http://mirrors.ctan.org/macros/latex/contrib/seqsplit/seqsplit.pdf
- http://mirrors.ctan.org/macros/latex/contrib/listings/listings.pdf
- How to get long \texttt sections to break
- http://en.wikibooks.org/wiki/LaTeX/Hyperlinks
And the following links for Highlighting and background color.
- Different background colors for lstinline
- How to redefine \lstinline to automatically highlight or draw frames around all inline code snippets?
- Background color in inline code listings with linebreak
- Colored background in inline listings
- Highlight text in code listing while also keeping syntax highlighting
- http://pleasemakeanote.blogspot.com/2009/08/how-to-highlight-text-in-latex.html
- Highlight text in code listing while also keeping syntax highlighting
It's very tedious to try every combination of techniques from both the sets but I tried many. It seems like the hard part is that both the applications use some kind of walk through technique, the first to calculate the line break points and the second to calculate the size of the box. If it wasn't inline then setting background color wouldn't require and fancy computation and this would be doable.
Summary
So in summary, how do I achieve the same output as above without having to manually insert line breaks? I don't want to worry about typesetting while typing the reports/journal entries.
Best Answer
Two types of macros are defined. The
\plaintt
breaks at line endings (without any additional hyphen character added). The other one\highlighttt
allows breaks only at dots, and colors the text. No break can occur in between dots.Update: I have made the thing a bit customizable. Let me comment on the difference between the two macros:
\highlighttt
has the disadvantage or advantage that breaks occur only at dots. But it has the big advantage that somewhat arbitrary TeX code in-between the dots can be used. See the first paragraph in the example, where I highlighted one sub-piece in blue.The second macro
\plaintt
accepts basically only letters and punctutations, but anything can be escaped from it by just putting it within braces. This is illustrated in the second paragraph.A hook is provided so that also
\plaintt
can do some highlighting, character per character. See the third paragraph where only\plaintt
is used, but the hook has been set to use the yellow box highlighting method.The highlighting method for
\highlighttt
is specified in the command\myhighlightmethod
.Only the use of the
txtt
font is hardcoded in the two macros, but of course this could be changed.