
説明項目にインラインリストを表示したいので、これを使用しました とても良い答えです残念ながら、このハッキングはエラーで私の定理環境を破壊しますsomething's wrong--perhaps a missing \item
問題を示す MWE は次のとおりです。
\documentclass{article}
\makeatletter
%%inline listings in description items
\let\orig@item\item
\def\item{%
\@ifnextchar{[}%
{\lstinline@item}%
{\orig@item}%
}
\begingroup
\catcode`\]=\active
\gdef\lstinline@item[{%
\setbox0\hbox\bgroup
\catcode`\]=\active
\let]\lstinline@item@end
}
\endgroup
\def\lstinline@item@end{%
\egroup
\orig@item[\usebox0]%
}
\makeatother
\usepackage{listings}
\lstloadlanguages{C++}
\lstset{
basicstyle=\ttfamily,
}
\usepackage{ntheorem}
\newtheorem{theorem}{Theorem}
\begin{document}
\section{Descriptions}
\begin{description}
\item[\lstinline{some verb text}] here is text
\item[\lstinline{some more}] more text
\end{description}
\section{Theorems}
\begin{theorem}[A Named theorem]
\begin{equation}
e^x = \sum_{k=1}^\infty \frac{x^k}{k!}
\end{equation}
\end{theorem}
\end{document}
両方を干渉せずに使用する方法はありますか?
答え1
を再定義する方法は使用せず\item
、 を使用するアイテムに対して特別なコマンドを使用します\lstinline
。
\documentclass{article}
\usepackage{ntheorem}
\usepackage{listings}
\makeatletter
%%inline listings in description items; it's a modified version of \lstinline
\newcommand\lstinlineitem[1][]{%
\setbox0=\hbox\bgroup % \lstinline has \leavevmode\bgroup
\aftergroup\finish@off@lstinlineitem % do something after building the box
\def\lst@boxpos{b}%
\lsthk@PreSet\lstset{flexiblecolumns,#1}%
\lsthk@TextStyle
\@ifnextchar\bgroup{\afterassignment\lst@InlineG \let\@let@token}%
\lstinline@}
\def\finish@off@lstinlineitem{\item[\usebox0]} % output the \item
\makeatother
\lstloadlanguages{C++}
\lstset{
basicstyle=\ttfamily,
}
\newtheorem{theorem}{Theorem}
\begin{document}
\section{Descriptions}
\begin{description}
\lstinlineitem{some verb text} here is text
\lstinlineitem!some verb %text! here is text
\lstinlineitem[basicstyle=\sffamily]+some more+ more text
\end{description}
\section{Theorems}
\begin{theorem}[A Named theorem]
\begin{equation}
e^x = \sum_{k=1}^\infty \frac{x^k}{k!}
\end{equation}
\end{theorem}
\end{document}
ご覧のとおり、 の構文全体が\lstinline
利用可能です。