The problem is that I have code fragment looking like this:

\detokenize{Some Funky Stuff 20%}

And texlive is saying that ! File ended while scanning use of \tabu@collectbody.. If I remove the % sign, the error goes away, but this sign has to be present there. If I however escape the % sign with a backslash \, then PDF is being generated, but with a backslash visible - in other words I see \% in PDF. How to do it the right way?

EDIT:

Didn't know it's important, but it seems it is - I'm experiencing this problem when working with tables, for example:

\begin{longtabu} to \linewidth {b{80pt}b{78pt}b{40pt}P{100pt}P{70pt}b{35pt}}
Start & End & Duration & Comment & Category & Lost Prod. {[kWh]} \\  \noalign{\vskip 2pt} \hline
\noalign{\vskip 4pt} \multicolumn{6}{l}{ \setrow{\bfseries} SOMETHING } \\
\rowfont{\small\baselineskip=5pt} 2016-09-02 19:20:00 & 2016-09-02 22:50:00 & 03,5:30:00 & {\catcode\%=12 \detokenize{Some Funky Stuff 20%}} & \detokenize{Utility} & 0 \\
\noalign{\vskip 2pt} \hline \noalign{\vskip 2pt}
\rowfont{\small\baselineskip=5pt} \multicolumn{2}{l}{Total for the stuff: } & \multicolumn{3}{l}{24.22:02:33 } & 640239,4 \\
\end{longtabu}

• why do you need detokenize here? just Funky Stuff 20\% would work, other use cases may need other solutions, \verb|Funky Stuff 20%| perhaps but.... Jul 20 '17 at 10:02
• Because sometimes other characters are appearing - like ampersand for example. Jul 20 '17 at 10:05

The \detokenize macro is similar to , but not the same as verbatim. In particular, braces need to be matched, and % are still used to discard the remains of the input record. One can work around that by redefining % to be the same catcode as a numerical digit, within the scope of the \detokenize.

\documentclass{article}
\begin{document}
{\catcode\%=12 \detokenize{Some Funky Stuff 20%}}

Here it is a comment again% BLAH
\end{document}


• It doesn't work :( . I'm using lualatex btw. Jul 20 '17 at 10:07
• @SzwornyDziąch What doesn't work about it? Do you mean in the context of your own code, or directly as my small example? For me, it works both in pdflatex as well as lualatex. Jul 20 '17 at 10:09
• Please see my edited question. Indeed your solution works in general, but my special case is tables :( Jul 20 '17 at 10:11
• Ok, I moved \catcode couple levels higher - to surround my table and now it works. Thanks! Jul 20 '17 at 10:14
• @SzwornyDziąch Seeing your tabu example, I was going to suggest exactly that... moving the \catcode scope around the complete longtabu. Jul 20 '17 at 10:15