내 자신의 \newenvironment에 \def 사용

내 자신의 \newenvironment에 \def 사용

증명서류 작성 명령어를 줄여서 명령어를 작성하려고 합니다. 현재 제가 사용하고 있던 것은

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

\begin{proof}이제 맨날 글쓰는게 지쳐서 \pf{ ...content... }or 로 바꾸고 싶네요 \pf[ ...content... ].

나는 노력했다

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

그것은 마음에 들지 않았습니다. 나는 이미 가지고 있다고 언급해야 한다

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

for 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. proofamsthm 및 그 환경 등을 사용합니다 .
  2. \newcommand이전 대신 사용하는 \def것은 매크로의 존재를 확인하는 새로운 매크로를 정의하는 LaTeX 방식입니다.

관련 정보