
Quero ter listagens inline nos itens de descrição, então usei isso resposta muito legal. Infelizmente, esse hacker destrói meus ambientes de teorema com errosomething's wrong--perhaps a missing \item
Aqui está o MWE que mostra o 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}
Existe uma maneira de usar as duas coisas sem interferir?
Responder1
Eu não usaria a abordagem de redefinir \item
, mas sim usaria um comando especial para itens que deseja 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 você pode ver, toda a sintaxe de \lstinline
está disponível.