声明TCBListing并将百分比写入文件

声明TCBListing并将百分比写入文件

mytcblisting我不明白为什么在写入百分比符号时环境会失败,我尝试过verbatim ignore percent但没有成功,出现错误:

! Missing \endcsname inserted.
<to be read again> 
                   \protect 
l.23 T
      his is my 5\percent\ text
? 

我正在使用 TeXLive 2020,这是我的示例文件:

\documentclass[10pt]{article}
\usepackage{tcolorbox}
\tcbuselibrary{listings,breakable,skins,xparse}
\DeclareTCBListing{mytcblisting}{ O{} }
  {%
    bottom=-1mm, boxrule=0.4pt, boxsep=0mm, top=-1mm, arc=0mm,%
    title~style={draw=none,fill=none}, enhanced, autoparskip, freelance,#1%
  }
\begin{document}
% OK, from doc pag 130
\def\percent{\%}
\begin{tcblisting}{title=Normal}
%\begin{center}\bfseries
This is my 5\percent\ text
and this is my 10\% text.
%\end{center}
\end{tcblisting}

% Error

\begin{mytcblisting}
%\begin{center}\bfseries
This is my 5\percent\ text
and this is my 10\% text.
%\end{center}
\end{mytcblisting}

\end{document}

答案1

您自己的列表已经因为没有任何百分号而失败。如果您title~style用替换title style,即没有~,它就可以正常工作。

\documentclass[10pt]{article}
\usepackage{tcolorbox}
\tcbuselibrary{listings,breakable,skins,xparse}
\DeclareTCBListing{mytcblisting}{ O{} }
  {%
     bottom=-1mm, boxrule=0.4pt, boxsep=0mm, top=-1mm, arc=0mm,%
     title style={draw=none,fill=none},
      enhanced, autoparskip, 
    freelance,#1%
  }
\begin{document}
% OK, from doc pag 130
\def\percent{\%}
\begin{tcblisting}{title=Normal}
%\begin{center}\bfseries
This is my 5\percent\ text
and this is my 10\% text.
%\end{center}
\end{tcblisting}

% No rror

\begin{mytcblisting}
%\begin{center}\bfseries
This is my 5\percent\ text
and this is my 10\% text.
%\end{center}
\end{mytcblisting}

\end{document}

在此处输入图片描述

当然,我假设这不是你的盒子的最终设计。我想我知道为什么有人认为必须添加一个~。好吧,这是一个漫长而不幸的讨论,没有必要进一步加剧它,特别是在这些疯狂的日子里。

相关内容