如何使“\verb”在帶有星號的分段命令版本中有效?

如何使“\verb”在帶有星號的分段命令版本中有效?

裡面好像\cprotect無效\verb有星標的版本切片命令\section*\paragraph*

如何解決這個問題?

% MWE
\documentclass{book}
\usepackage{cprotect}
\begin{document}
\cprotect\part*{text and \verb"\verb"}
\cprotect\chapter*{text and \verb"\verb"}
\cprotect\section*{text and \verb"\verb"}
\cprotect\subsection*{text and \verb"\verb"}
\cprotect\subsubsection*{text and \verb"\verb"}
\cprotect\paragraph*{text and \verb"\verb"}
\cprotect\subparagraph*{text and \verb"\verb"}
\end{document}

答案1

在此輸入影像描述

\documentclass{book}
\usepackage{cprotect}
\begin{document}
\cprotect{\part*}{text and \verb"\verb"}
\cprotect{\chapter*}{text and \verb"\verb"}
\cprotect{\section*}{text and \verb"\verb"}
\cprotect{\subsection*}{text and \verb"\verb"}
\cprotect{\subsubsection*}{text and \verb"\verb"}
\cprotect{\paragraph*}{text and \verb"\verb"}
\cprotect{\subparagraph*}{text and \verb"\verb"}
\end{document}

相關內容