Redefining commands in a new environment

2019-04-04 15:05发布

Two questions:

  1. Does LaTeX allow one to (re)define commands within a \newenvironment? I've tried using \renewcommand, \newcommand and \def in the before declaration but to no avail.

  2. How would one redefine \item when creating a new list environment?

I've created a new type of list environment from scratch using \newenvironment while using another token instead of \item for each but I'd really like to keep things consistent by using \list and redefining \item.

标签: latex tex
2条回答
男人必须洒脱
2楼-- · 2019-04-04 15:38

Too late perhaps, but it may be useful for someone else

\newenvironment{coolitemize}{%
\let\olditem\item% 
\renewcommand\item[2][]{\olditem \textbf{##1}\\[0.3\baselineskip]##2}%
\begin{itemize}}{\end{itemize}%
}

and use it

\begin{coolitemize}
\item[Title of my first item] Text of my 1st item.
\item[Second one] And some text here.
\end{coolitemize}
查看更多
狗以群分
3楼-- · 2019-04-04 15:50

Sure; it's hard to know what went wrong without seeing your code. As an answer to your two questions, see if this helps:

\documentclass{article}
\begin{document}
\newenvironment{myitemize}{%
  \begin{list}{}{}% whatever you want the list to be
  \let\olditem\item
  \renewcommand\item{\olditem ITEM: }
}{%
  \end{list}
}  
\begin{myitemize}
\item one \item two
\end{myitemize}
\end{document}
查看更多
登录 后发表回答