
Quiero tener listados en línea en los elementos de descripción, así que usé esto muy buena respuesta. Desafortunadamente, este hackeo destruye mis entornos de teoremas con error.something's wrong--perhaps a missing \item
Aquí está el MWE que muestra el problema:
\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}
¿Hay alguna manera de usar ambas cosas sin interferir?
Respuesta1
No usaría el enfoque de redefinir \item
, sino que usaría un comando especial para los elementos que quieran usar \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}
Como puede ver, toda la sintaxis de \lstinline
está disponible.