\begin{...}
そのような環境でない場合は環境を開始 ( 's it) し、そのような環境の場合は環境を閉じる ( 's it) ようなコマンドを定義したいと思います\end{...}
。例:
\myenum
\item Item A
\item Item B
\myenum
もちろん、これはmyenum
環境をネストできないことを意味します。そのようなコマンドを定義する方法を誰か知っていますか?
答え1
これがどれほど役に立つかはわかりません。もちろん、ネストは不可能です。
\documentclass{article}
\usepackage{pdftexcmds}
\makeatletter
\catcode`*=\active
\def*{\@ifnextchar*{\check@enumerate}{\item}}
\def\check@enumerate{%
\ifnum\pdf@strcmp{\@currenvir}{enumerate}=\z@
% we're already in enumerate
\end{enumerate}
\else
\begin{enumerate}
\fi
\@gobble
}
\makeatother
\begin{document}
Some text which we try to make long enough to reach
the right margin, so that we can see a line break
before the \texttt{enumerate} environment.
**
* First
* Second
**
Some other text which we try to make long enough to reach
the right margin, so that we can see a line break
after the \texttt{enumerate} environment.
\end{document}
expl3
同じものの実装:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\cs_new:Nn \carucel_item_or_enum:
{
\peek_charcode_remove:NTF *
{
\carucel_enum:
}
{
\item
}
}
\cs_new:Nn \carucel_enum:
{
\tl_if_eq:vnTF { @currenvir } { enumerate }
{
\end{enumerate}
}
{
\begin{enumerate}
}
}
\cs_generate_variant:Nn \tl_if_eq:nnTF { v }
\char_set_catcode_active:N *
\cs_set_eq:NN * \carucel_item_or_enum:
\ExplSyntaxOff
\begin{document}
Some text which we try to make long enough to reach
the right margin, so that we can see a line break
before the \texttt{enumerate} environment.
**
* First
* Second
**
Some other text which we try to make long enough to reach
the right margin, so that we can see a line break
after the \texttt{enumerate} environment.
\end{document}