Since the question clearly references the answer at this question: Line break in texttt, I'll take a stab.
For whatever reason, the use of \hl
inside of the revised \texttt
causes truncation by the amount of special/active characters (/
, [
, .
) inside the string. The only solution is to pad the input string by that number of extra tokens, so that \hl
eats up the desired string, while leaving the padding behind.
While I did not yet find a way to do this on-the-fly inside of the \texttt
, I did figure out how to do it if alerted before entering \texttt
. Thus, the macro \HLtt{}
is used to highlight the complete \texttt
string (rather than just a piece of it).
It works (before invoking \textt
) by passing the argument to listofitems
to count the special characters. Then it adds one x
to \tmp
for each occurrence of a special character. Finally it invokes \textt
with the original argument plus the padding.
\documentclass[a4paper]{article}
\usepackage{listofitems}
\setsepchar[?]{/||[||.}% SET THE CHARS TO SEARCH FOR
\newcommand\HLtt[1]{%
\readlist\tmplist{#1}% FIND THE SEARCHED FOR CHARS (CALL IT n)
\def\tmp{}%
\foreachitem\x\in\tmplist[]{% CREATE A STRING OF n-1 TOKENS
\ifnum\xcnt=1\relax\else%
\expandafter\def\expandafter\tmp\expandafter{\tmp x}\fi}%
\def\tmpA{#1}%
\expandafter\expandafter\expandafter\texttt%
\expandafter\expandafter\expandafter{%
\expandafter\expandafter\expandafter\hl%
\expandafter\expandafter\expandafter{%
\expandafter\tmpA\tmp}}%
}
\renewcommand{\texttt}[1]{%
\begingroup
\ttfamily
\begingroup\lccode`~=`/\lowercase{\endgroup\def~}{/\discretionary{}{}{}}%
\begingroup\lccode`~=`[\lowercase{\endgroup\def~}{[\discretionary{}{}{}}%
\begingroup\lccode`~=`.\lowercase{\endgroup\def~}{.\discretionary{}{}{}}%
\catcode`/=\active\catcode`[=\active\catcode`.=\active
\scantokens{#1\noexpand}%
\endgroup
}
\usepackage{soul,xcolor}
\begin{document}
If an unrecoverable error occurs during the transformation, then a
\texttt{javax.xml.transform.TransformerException} is thrown.
If an unrecoverable error occurs during the transformation, then a
\HLtt{\$GLOBALS['TCA']['tt\_address']['feInterface']['fe\_admin\_fieldList']}
\HLtt{\$GLOBALS['TCA']['tt\_address']['feInterface']}
\HLtt{\$GLOBALS['TCA']['tt\_address']}
\HLtt{\$GLOBALS['TCA']}
\end{document}