Configurando o ambiente para rotular equações de forma automática e aleatória com símbolos

Configurando o ambiente para rotular equações de forma automática e aleatória com símbolos

Assim, usando o ambiente de equações e \label{ ... }, é fácil obter equações que são numeradas automaticamente em um documento. Se quisermos personalizar o símbolo que rotula o documento, podemos usar \tag{ ... }.

No entanto, existe uma boa maneira de configurar o ambiente para que, dentro de um documento específico, as equações sejam automaticamente rotuladas com símbolos aleatórios? Aqui, o conjunto de símbolos potenciais seria especificado antecipadamente em algum lugar do documento, e equações diferentes receberiam símbolos diferentes.

Responder1

OpgfO pacote fornece os comandos \pgfmathdeclarerandomlistpara \pgfmathrandomitemtrabalhar com listas aleatórias. Como você provavelmente deseja usar os rótulos das equações no máximo uma vez, a melhor opção é excluir os itens da lista sempre que eles forem usados, o que é difícil. Felizmente, Mark Wibrow oferece uma maneira de fazer isso em sua resposta à perguntaComo faço para gerar em LaTeX uma lista de questões aleatórias evitando repetições?.

Armado com o código de Mark, é muito fácil fazer o que você deseja usar \tagpara adicionar um rótulo aleatório de uma lista de rótulos especificada pelo usuário:

insira a descrição da imagem aqui

Aqui está o código:

\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}

Algumas observações:

  • A parte difícil é feita pelo código do Wibrow para\pgfmathrandomitemwithoutreplacement
  • as equações são compostas dentro de um ambiente de equação normal
  • os rótulos das equações são definidos usando\EquationLabels
  • se houver mais equações do que rótulos, você receberá um erro não informativo do PGF Math Error dizendo que a lista aleatória equationlabelsestá vazia.

Responder2

Você pode definir a sequência de numeração de símbolos predeterminada usando \ifcasecomo redefinição de \theequation:

insira a descrição da imagem aqui

\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}

informação relacionada