improve code package: deactivate | symbol in tables. make | and code usable inside other macros by rescanning the token list

This commit is contained in:
Maximilian Keßler 2022-02-10 01:26:33 +01:00
parent 371ce76a81
commit 0a902cc0ec

View file

@ -4,6 +4,9 @@ __NEW_IF__(pipe,false)
\DeclareOption{pipe}{__SET_IF__(pipe,true)} \DeclareOption{pipe}{__SET_IF__(pipe,true)}
\ProcessOptions \ProcessOptions
% This is needed in general: when _ is active, we want it to expand to
% an actual _ character
\catcode`_=13 \catcode`_=13
\let_\_ \let_\_
\catcode`_=8 \catcode`_=8
@ -20,20 +23,12 @@ __NEW_IF__(pipe,false)
} }
\ExplSyntaxOff \ExplSyntaxOff
\newif\ifactive\activefalse
__IF__(pipe) __IF__(pipe)
\catcode`|=\active \catcode`|=\active
\def|{ \def|#1|{
\ifactive \code{#1}
\endgroup
\activefalse
\else
\begingroup
\catcode`_=13
\ttfamily
\fi
} }
% Quick fix for tables % Do not make | active inside tables
\AddToHook{env/tabular/begin}[code]{\catcode`|=13} \AddToHook{env/tabular/before}[code]{\catcode`|=12}
\AddToHook{env/tabular/end}[code]{\catcode`|=8} \AddToHook{env/tabular/after}[code]{\catcode`|=13}
\fi \fi