
Lo que básicamente quiero es escribir una lista única, por ejemplo, detallar, etiquetar cada elemento con una o más etiquetas y luego generar una salida que cree múltiples listas basadas en las etiquetas, es decir, cada etiqueta debe ser una sección o algo así:
ya encontréeste:
\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}
Pero esto parece no ser apropiado, sólo se puede usar una etiqueta por artículo.
¿Hay algo que haga esto? Ya pensé en implementar mi propio paquete pero no estoy familiarizado con la programación tex.
Actualizar
Encontré una manera de modificar el código publicado para lograr la clasificación con respecto a múltiples etiquetas:
\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}
Por lo tanto, especifique de antemano la cantidad de etiquetas que desea utilizar. Esto funciona, pero no es práctico; sería fantástico si alguien supiera cómo crear esta dinámica.
Si alguien quiere utilizar o contribuir:https://github.com/maalaria/kite
Respuesta1
El siguiente ejemplo proporciona el pro
entorno para tomar un único argumento obligatorio que puede contener una lista de etiquetas separadas por comas. Para cada etiqueta, el entorno \BODY
se almacena en una macro <tag>@<num>
, que luego se puede imprimir en secuencia a través de \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}
El procesamiento del archivo se realiza utilizando \processfile{<file>}
.
No se realiza ninguna verificación de errores para ver si <tag>
existe con una llamada a \processlist{<tag>}
pero podría agregarse.