방정식에 기호를 사용하여 자동으로 무작위로 레이블을 지정하는 환경 설정

방정식에 기호를 사용하여 자동으로 무작위로 레이블을 지정하는 환경 설정

따라서 방정식 환경과 을 사용하면 \label{ ... }문서에서 자동으로 번호가 매겨진 방정식을 쉽게 얻을 수 있습니다. 문서에 라벨을 붙인 기호를 사용자 정의하려면 를 사용할 수 있습니다 \tag{ ... }.

그러나 지정된 문서 내에서 방정식에 무작위 기호로 자동 레이블이 지정되도록 환경을 설정하는 좋은 방법이 있습니까? 여기에서 잠재적인 기호 집합은 문서 어딘가에 미리 지정되며, 다른 방정식에는 다른 기호가 할당됩니다.

답변1

그만큼pgf패키지는 명령을 제공 \pgfmathdeclarerandomlist하고\pgfmathrandomitem 임의 목록 작업을 제공합니다. 아마도 방정식 레이블을 최대 한 번만 사용하고 싶기 때문에 가장 좋은 옵션은 사용할 때마다 목록 항목을 삭제하는 것입니다. 이는 어렵습니다. 다행스럽게도 Mark Wibrow는 질문에 대한 답변에서 이를 수행하는 방법을 제공합니다.반복을 피하는 무작위 질문 목록을 LaTeX에서 어떻게 생성합니까?.

\tagMark의 코드를 사용하면 사용자가 지정한 레이블 목록에서 임의의 레이블을 추가하는 데 사용하여 원하는 작업을 수행하는 것이 매우 쉽습니다 .

여기에 이미지 설명을 입력하세요

코드는 다음과 같습니다.

\documentclass{article}
\usepackage{pgf}
\usepackage{amsmath}

\newcommand\EquationLabels[1]{%
  \pgfmathsetseed{\number\day\number\time}% set a "random" seed based on time
  \pgfmathdeclarerandomlist{equationlabels}{#1}%
}

\newenvironment{Equation}{\equation}%
   {\pgfmathrandomitemwithoutreplacement{\rtag}{equationlabels}\tag{\rtag}\endequation}

% Mark Wibrow: https://tex.stackexchange.com/questions/113987/how-do-i-generate-in-latex-a-list-of-random-questions-avoiding-repetitions
\makeatletter
\def\pgfmathrandomitemwithoutreplacement#1#2{%
    \pgfmath@ifundefined{pgfmath@randomlist@#2}{\pgfmath@error{Unknown random list `#2'}}{%
        \edef\pgfmath@randomlistlength{\csname pgfmath@randomlist@#2\endcsname}%
        \ifnum\pgfmath@randomlistlength>0\relax%
            \pgfmathrandominteger{\pgfmath@randomtemp}{1}{\pgfmath@randomlistlength}%
            \def\pgfmath@marshal{\def#1}%
            \expandafter\expandafter\expandafter\pgfmath@marshal\expandafter\expandafter\expandafter{\csname pgfmath@randomlist@#2@\pgfmath@randomtemp\endcsname}%
            % Now prune.
            \c@pgfmath@counta=\pgfmath@randomtemp\relax%
            \c@pgfmath@countb=\c@pgfmath@counta%
            \advance\c@pgfmath@countb by1\relax%
            \pgfmathloop%
            \ifnum\c@pgfmath@counta=\pgfmath@randomlistlength\relax%
            \else%
                \def\pgfmath@marshal{\expandafter\global\expandafter\let\csname pgfmath@randomlist@#2@\the\c@pgfmath@counta\endcsname=}%
                \expandafter\pgfmath@marshal\csname pgfmath@randomlist@#2@\the\c@pgfmath@countb\endcsname%
                \advance\c@pgfmath@counta by1\relax%
                \advance\c@pgfmath@countb by1\relax%
            \repeatpgfmathloop%
            \advance\c@pgfmath@counta by-1\relax%
            \expandafter\xdef\csname pgfmath@randomlist@#2\endcsname{\the\c@pgfmath@counta}%
        \else%
            \pgfmath@error{Random list `#2' is empty}%
        \fi%
    }}
\makeatletter

\begin{document}

  % set some labels
  \EquationLabels{{$\spadesuit$}{$\heartsuit$}{$\diamondsuit$}{$\clubsuit$}}

  \begin{Equation}1+1=2\end{Equation}

  \begin{Equation}1+2=3\end{Equation}

  \begin{Equation}1+3=4\end{Equation}

  \begin{Equation}1+4=5\end{Equation}

  % a longer list of labels
  \EquationLabels{abcdefghijklmnopqrstuvwxyz}

  \begin{Equation}1+1=2\end{Equation}

  \begin{Equation}1+2=3\end{Equation}

  \begin{Equation}1+3=4\end{Equation}

  \begin{Equation}1+4=5\end{Equation}

\end{document}

몇 가지 참고사항:

  • 어려운 부분은 Wibrow의 코드로 수행됩니다.\pgfmathrandomitemwithoutreplacement
  • 방정식은 일반 방정식 환경 내에서 조판됩니다.
  • 방정식의 레이블은 다음을 사용하여 설정됩니다.\EquationLabels
  • 레이블보다 방정식이 더 많으면 PGF 수학 오류에서 무작위 목록이 비어 있다는 정보 없는 오류가 발생합니다 equationlabels.

답변2

\ifcase다음을 재정의하여 미리 결정된 기호 번호 지정 순서를 설정할 수 있습니다 \theequation.

여기에 이미지 설명을 입력하세요

\documentclass{article}

\renewcommand{\theequation}{%
  \ifcase\value{equation}%
    \or $\spadesuit$% 1
    \or $\heartsuit$% 2
    \or $\clubsuit$% 3
    \or $\diamondsuit$% 4
    \or $\star$% 5
    \or $\alpha$% 6
    \or $\beta$% 7
    \or $\gamma$% 8
    \or $\epsilon$% 9
    \else \arabic{equation}% 10...
  \fi
}

\begin{document}

\begin{equation}  1 +   2 =   3 \end{equation}
\begin{equation}  2 +   3 =   5 \end{equation}
\begin{equation}  3 +   5 =   8 \end{equation}
\begin{equation}  5 +   8 =  13 \end{equation}
\begin{equation}  8 +  13 =  21 \end{equation}
\begin{equation} 13 +  21 =  34 \end{equation}
\begin{equation} 21 +  34 =  55 \end{equation}
\begin{equation} 34 +  55 =  89 \end{equation}
\begin{equation} 55 +  89 = 144 \end{equation}
\begin{equation} 89 + 144 = 233 \end{equation}

\end{document}

관련 정보