Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \documentclass{article}
- \usepackage{pgffor,environ}
- \newcommand{\proit}{\noexpand\textit}
- \newcommand{\probf}{\noexpand\textbf}
- \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 \probf{no \proit{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}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement