独自の\newenvironmentに\defを使用する

独自の\newenvironmentに\defを使用する

証明を書くためのコマンドを短縮するコマンドを書こうとしています。現時点では、

\newenvironment{proof}%
{\textbf{Proof:}}%
{\begin{flushright} $\blacksquare$ \end{flushright}}

\begin{proof}今はずっと書くのに疲れてきたので、\pf{ ...content... }またはに切り替えたいと思っています\pf[ ...content... ]

やってみた

\def\pf[#2\]{\begin{proof} #2 \end{proof}}

それは気に入らなかった。私はすでに

\def\[#1\]{\begin{align}#1\end{align}}

なのでalign、 にはそれを使用しませんでしたproof

答え1

強くお勧めしますないこれを実行します。ただし、これはおそらく、これまでに行ったことほど悪くはありませんalign。必要な場合は、次の操作を実行してください。

\documentclass{article}
\usepackage{xparse,amssymb}
\NewDocumentCommand \pf { +r[] } {%
  \noindent\textbf{Proof:}
    #1\hspace*{\fill}\nolinebreak$\blacksquare$}

\begin{document}

 \pf[
   Alice saw Nobody on the road, whereas the King did not.\\
   So, Alice has sharper eyes than the King and Nobody is travelling on the road.]
 \pf[
   Alice saw Nobody on the road, whereas the King did not.\\
   Hence, Alice has sharper eyes than the King.]

\end{document}

速記証明

編集:改行/ページ区切りを少しうまく処理します。[ただし、上で述べたように、これは実際には良い方法ではありません。コードのわかりやすさを維持しながら、これを適切に処理するように設計されたパッケージと環境があります。]

答え2

これをお勧めはしませんが、これは機能します(保証なし)

\documentclass{article}
\usepackage{amsmath,amssymb}
\newenvironment{proof}%
{\textbf{Proof:}}%
{\hfill$\blacksquare$}
\def\pf#1{\begin{proof} #1 \end{proof}}
\begin{document}
  \pf{some proof here}
\end{document}

ここに画像の説明を入力してください

それはさらにいいです

  1. amsthm とその環境を使用するproofなど。
  2. \newcommand代わりに前者を使用することは\def、マクロの存在をチェックする新しいマクロを定義する LaTeX の方法です。

関連情報