![声明TCBListing并将百分比写入文件](https://linux22.com/image/410999/%E5%A3%B0%E6%98%8ETCBListing%E5%B9%B6%E5%B0%86%E7%99%BE%E5%88%86%E6%AF%94%E5%86%99%E5%85%A5%E6%96%87%E4%BB%B6.png)
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}
当然,我假设这不是你的盒子的最终设计。我想我知道为什么有人认为必须添加一个~
。好吧,这是一个漫长而不幸的讨论,没有必要进一步加剧它,特别是在这些疯狂的日子里。