
o que eu basicamente quero é escrever uma única lista, por exemplo, itemizar, marcar cada item com uma ou mais tags e então gerar uma saída que crie múltiplas listas com base nas tags, ou seja, cada tag deve ser uma seção ou algo assim:
eu já encontreiesse:
\documentclass{article}
\usepackage{pgffor}
\usepackage{xstring}
\usepackage{environ}
\usepackage{filecontents}
\begin{filecontents*}{foo.tex}
\begin{pro}{Geometry}
Find the area of ...
\end{pro}
\begin{pro}{Trigonometry}
The angle ...
\end{pro}
\begin{pro}{Algebra}
Prove that $x^2+1=0$ has no real solution.
\end{pro}
\begin{pro}{Geometry}
Find the radius ...
\end{pro}
\end{filecontents*}
\NewEnviron{pro}[1]{%
\IfStrEq{#1}{\CurrentSubject}{\item \BODY}{}
}%
\newcommand*{\CurrentSubject}{}%
\begin{document}
\foreach \Title in {Algebra, Geometry, Trigonometry} {%
\renewcommand*{\CurrentSubject}{\Title}%
\section*{\CurrentSubject}
\begin{enumerate}
\input{foo}
\end{enumerate}
}%
\end{document}
Mas isso parece não ser apropriado, só é possível usar uma tag por item.
Existe algo que faz isso. Já pensei em implementar meu próprio pacote mas não estou familiarizado com programação tex.
Atualizar
Encontrei uma maneira de modificar o código postado para obter a classificação em relação a várias tags:
\documentclass{article}
\usepackage{pgffor}
\usepackage{xstring}
\usepackage{environ}
\usepackage{filecontents}
\begin{filecontents*}{foo.tex}
\begin{pro}{Geometry}{}{}{}{}
Find the area of ...
\end{pro}
\begin{pro}{Trigonometry}{}{}{}{}
The angle ...
\end{pro}
\begin{pro}{Algebra}{Trigonometry}{}{}{}
Prove that $x^2+1=0$ has no real solution.
\end{pro}
\begin{pro}{Geometry}{Algebra}{}{}{}
Find the radius ...
\end{pro}
\end{filecontents*}
\NewEnviron{pro}[5]{%
\IfStrEq{#1}{\CurrentSubject}{\item \BODY}{}
\IfStrEq{#2}{\CurrentSubject}{\item \BODY}{}
\IfStrEq{#3}{\CurrentSubject}{\item \BODY}{}
\IfStrEq{#4}{\CurrentSubject}{\item \BODY}{}
\IfStrEq{#5}{\CurrentSubject}{\item \BODY}{}
}%
\newcommand*{\CurrentSubject}{}%
\begin{document}
\foreach \Title in {Algebra, Geometry, Trigonometry} {%
\renewcommand*{\CurrentSubject}{\Title}%
\section*{\CurrentSubject}
\begin{enumerate}
\input{foo}
\end{enumerate}
}%
\end{document}
Portanto, especifique antecipadamente uma série de tags que deseja usar. Isso funciona, mas não é prático - seria ótimo se alguém soubesse como tornar isso dinâmico.
Se alguém quiser usar ou contribuir:https://github.com/maalaria/kite
Responder1
O exemplo a seguir fornece o pro
ambiente para usar um único argumento obrigatório que pode conter uma lista de tags separadas por vírgula. Para cada tag, o ambiente \BODY
é armazenado em uma macro <tag>@<num>
, que pode ser impressa em sequência via \printlist{<tag>}
.
\documentclass{article}
\usepackage{pgffor,environ}
\usepackage{filecontents}
\begin{filecontents*}{foo.tex}
\begin{pro}{Geometry}
Find the area of \ldots
\end{pro}
\begin{pro}{Trigonometry}
The angle \ldots
\end{pro}
\begin{pro}{Algebra,Trigonometry}
Prove that $x^2 + 1 = 0$ has no real solution.
\end{pro}
\begin{pro}{Geometry,Algebra}
Find the radius \ldots
\end{pro}
\end{filecontents*}
\makeatletter
\NewEnviron{pro}[1]{%
\foreach \Title in {#1} {%
\expandafter\ifcsname c@\Title\endcsname\else% If a counter doesn't exist...
\newcounter{\Title}% ... create it
\fi
\stepcounter{\Title}% Another element should be added to particular list
\edef\x{% Add element to particular list
\noexpand\expandafter\noexpand\protected@xdef
\noexpand\csname \Title @\csname the\Title\endcsname\noexpand\endcsname{\BODY}}\x
}
}
\makeatother
\newcommand{\processfile}[1]{\input{#1}}
\newcommand{\printlist}[2][itemize]{%
\expandafter\let\expandafter\listend\csname the#2\endcsname
\begin{#1}
\foreach \curitem in {1,...,\listend} {
\item \expandafter\csname #2@\curitem\endcsname
}
\end{#1}
}
\begin{document}
\processfile{foo}% Process file with pro environments
Algebra:
\printlist{Algebra}
Geometry:
\printlist{Geometry}
Trigonometry:
\printlist{Trigonometry}
\end{document}
O processamento do arquivo é feito usando \processfile{<file>}
.
Nenhuma verificação de erros é feita para ver se <tag>
existe uma chamada para \processlist{<tag>}
, mas pode ser adicionada.