答案1
答案2
使用选项shortverb
,并且\MakeShortVerb|
已经在https://tex.stackexchange.com/a/665018/2388所以这里有一个替代方案fancyvrb
:
\documentclass{article}
\usepackage{fancyvrb}
\DefineShortVerb{\|}
\begin{document}
|\a\b!|
\end{document}
答案3
正如Ulrike Fischer
所说:
\documentclass{article}
\usepackage{shortvrb}
\MakeShortVerb|
\begin{document}
Hello, |\a\b|!
\end{document}
答案4
将包包含shortvrb
在您的 .tex 文件中。
(版权所有 1993-2022 LaTeX3 项目。)
\makeatletter
\def\MakeShortVerb{%
\@ifstar
{\def\@shortvrbdef{\verb*}\@MakeShortVerb}%
{\def\@shortvrbdef{\verb}\@MakeShortVerb}}
\def\@MakeShortVerb#1{%
\expandafter\ifx\csname cc\string#1\endcsname\relax
\@shortvrbinfo{Made }{#1}\@shortvrbdef
\add@special{#1}%
\expandafter
\xdef\csname cc\string#1\endcsname{\the\catcode`#1}%
\begingroup
\catcode`\~\active \lccode`\~`#1%
\lowercase{%
\global\expandafter\let
\csname ac\string#1\endcsname~%
\expandafter\gdef\expandafter~\expandafter{\@shortvrbdef~}}%
\endgroup
\global\catcode`#1\active
\else
\@shortvrbinfo\@empty{#1 already}{\@empty\verb(*)}%
\fi}
\def\DeleteShortVerb#1{%
\expandafter\ifx\csname cc\string#1\endcsname\relax
\@shortvrbinfo\@empty{#1 not}{\@empty\verb(*)}%
\else
\@shortvrbinfo{Deleted }{#1 as}{\@empty\verb(*)}%
\rem@special{#1}%
\global\catcode`#1\csname cc\string#1\endcsname
\global \expandafter\let \csname cc\string#1\endcsname \relax
\ifnum\catcode`#1=\active
\begingroup
\catcode`\~\active \lccode`\~`#1%
\lowercase{%
\global\expandafter\let\expandafter~%
\csname ac\string#1\endcsname}%
\endgroup \fi \fi}
\def\@shortvrbinfo#1#2#3{%
\PackageInfo{shortvrb}{%
#1\expandafter\@gobble\string#2 a short reference
for \expandafter\string#3}}
\def\add@special#1{%
\rem@special{#1}%
\expandafter\gdef\expandafter\dospecials\expandafter
{\dospecials \do #1}%
\expandafter\gdef\expandafter\@sanitize\expandafter
{\@sanitize \@makeother #1}}
\def\rem@special#1{%
\def\do##1{%
\ifnum`#1=`##1 \else \noexpand\do\noexpand##1\fi}%
\xdef\dospecials{\dospecials}%
\begingroup
\def\@makeother##1{%
\ifnum`#1=`##1 \else \noexpand\@makeother\noexpand##1\fi}%
\xdef\@sanitize{\@sanitize}%
\endgroup}
\makeatother