I write a LaTeX manual in memoir class with the Minted package, TeXlive 2021 and TeXmaker.
To insert some \mintinline code in a Tabularx X-type column, I used this trick and it work. Except that it produce a "detokenized verbatim command" with spaces after detokenized command name and I want to remove them (or any other unwanted spaces). Also, I want to keep the same form that a \mintinline code outside a tabularx environment.
For that, I tried many many solutions (this one with the apparently uneffective macro \detokenizeplus or those one) and none of them work (or I'm just too bad for it), inside or outside the tabularx environment. The closest solution is to use the tokcycle package and his macro \altdetokenize, which, at least, work outside the tabularx environment.
To proceed, I had rewrote the definition of the mintinline macro, like in the following MWE (see the comments). It remove error at the compilation and I produce the wanted mintinline result, but I don't understand why it keep those unwanted spaces (I suppose that it's beyond my LaTeX skills) and I need your help :
\documentclass[twoside,a4paper,11pt]{memoir}
\usepackage[T1]{fontenc}
\usepackage{tabularx}
\usepackage{minted}
\usepackage{tokcycle}
\newif\ifmacro
\newcommand\altdetokenize[1]{\begingroup\stripgroupingtrue\macrofalse
\stripimplicitgroupingcase{-1}%
\tokcycle
{\ifmacro\def\tmp{##1}\ifcat\tmp A\else\unskip\allowbreak\fi\macrofalse\fi
\detokenize{##1}\ifx##1\bgroup\unskip\fi\ifx##1\egroup\unskip\fi}
{\ifmacro\unskip\macrofalse\fi{\processtoks{##1}\ifmacro\unskip\fi}\allowbreak}
{\tctestifx{\##1}{\}{\ifmacro\unskip\allowbreak\fi
\allowbreak\detokenize{##1}\macrotrue}}
{\hspace{0pt plus 3em minus .3ex}}
{#1}%
\unskip
\endgroup}
\makeatletter
\renewrobustcmd{\mintinline}[2][]{%
\begingroup
\setboolean{minted@isinline}{true}%
\minted@configlang{#2}%
\setkeys{minted@opt@cmd}{#1}%
\minted@fvset
\begingroup
\let\do@makeother\dospecials
\catcode\{=1 \catcode}=2
\catcode\^^I=\active \@ifnextchar\bgroup {\minted@inline@iii}% {\catcode{=12\catcode\}=12 \minted@inline@i}} \def\minted@inline@i#1{% \endgroup \def\minted@inline@ii##1#1{% \minted@inline@iii{##1}}% \begingroup \let\do\@makeother\dospecials \catcode^^I=\active
\minted@inline@ii}
\ifthenelse{\boolean{minted@draft}}%
{\renewcommand{\minted@inline@iii}[1]{%
\endgroup
\begingroup
\minted@defwhitespace@retok
\everyeof{\noexpand}%
\endlinechar-1\relax
\let\do@makeother\dospecials
\catcode\ =\active \catcode^^I=\active
\xdef\minted@tmp{\scantokens{#1}}%
\endgroup
\let\FV@Line\minted@tmp
\def\FV@SV@minted@tmp{%
\FV@Gobble
\expandafter\FV@ProcessLine\expandafter{\FV@Line}}%
\ifthenelse{\equal{\minted@get@opt{breaklines}{false}}{true}}%
{\let\FV@BeginVBox\relax
\let\FV@EndVBox\relax
\def\FV@BProcessLine##1{\FancyVerbFormatLine{##1}}%
\BUseVerbatim{minted@tmp}}%
{\BUseVerbatim{minted@tmp}}%
\endgroup}}%
{\renewcommand{\minted@inline@iii}[1]{%
\endgroup
\minted@writecmdcode{#1}%
\RecustomVerbatimEnvironment{Verbatim}{BVerbatim}{}%
\setcounter{minted@FancyVerbLineTemp}{\value{FancyVerbLine}}%
\ifx@footnotetext\TX@trial@ftn% <===== test if the macro is inside tabularx environment
\altdetokenize{\minted@pygmentize{\minted@lang}}% <===== detokenize the token to avoid error (and supposed without unwanted space but it won't work)
\else
\minted@pygmentize{\minted@lang}% <===== normal behavior if outside of
\fi
\setcounter{FancyVerbLine}{\value{minted@FancyVerbLineTemp}}%
\endgroup}}
\makeatother
\begin{document}
Text with \mintinline{latex}{\inlinecode\without\space\after\command}.\
\begin{tabularx}{\linewidth}{ X }
\toprule
\mintinline{latex}{\inlinecode\without\space\after\command} \
\bottomrule
\end{tabularx}
\end{document}
If you can show me a elegant solution, I will be grateful !
minted. However, I can say thattokcycleand thus\altdetokenizework upon the unexpanded tokens of their input stream/argument. Thus, when yu say\altdetokenize{\minted@pygmentize{\minted@lang}}, it is literally those tokens being detokenized, not what they later expand to. – Steven B. Segletes May 07 '21 at 17:54