Advertisement
Guest User

Untitled

a guest
Jul 18th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 1.49 KB | None | 0 0
  1. \documentclass{article}
  2.  
  3. \usepackage{pgffor,environ}
  4.  
  5. \newcommand{\proit}{\noexpand\textit}
  6. \newcommand{\probf}{\noexpand\textbf}
  7.  
  8. \usepackage{filecontents}
  9. \begin{filecontents*}{foo.tex}
  10. \begin{pro}{Geometry}
  11. Find the area of \ldots
  12. \end{pro}
  13.  
  14. \begin{pro}{Trigonometry}
  15. The angle \ldots
  16. \end{pro}
  17.  
  18. \begin{pro}{Algebra,Trigonometry}
  19. Prove that $x^2 + 1 = 0$ has \probf{no \proit{real solution}}.
  20. \end{pro}
  21.  
  22. \begin{pro}{Geometry,Algebra}
  23. Find the radius \ldots
  24. \end{pro}
  25. \end{filecontents*}
  26.  
  27. \makeatletter
  28. \NewEnviron{pro}[1]{%
  29.   \foreach \Title in {#1} {%
  30.     \expandafter\ifcsname c@\Title\endcsname\else% If a counter doesn't exist...
  31.       \newcounter{\Title}%                         ... create it
  32.     \fi
  33.     \stepcounter{\Title}% Another element should be added to particular list
  34.     \edef\x{% Add element to particular list
  35.       \noexpand\expandafter\noexpand\protected@xdef
  36.         \noexpand\csname \Title @\csname the\Title\endcsname\noexpand\endcsname{\BODY}}\x
  37.  
  38.  }
  39. }
  40. \makeatother
  41.  
  42. \newcommand{\processfile}[1]{\input{#1}}
  43.  
  44. \newcommand{\printlist}[2][itemize]{%
  45.   \expandafter\let\expandafter\listend\csname the#2\endcsname
  46.   \begin{#1}
  47.    \foreach \curitem in {1,...,\listend} {
  48.      \item \expandafter\csname #2@\curitem\endcsname
  49.    }
  50.  \end{#1}
  51. }
  52.  
  53. \begin{document}
  54.  
  55. \processfile{foo}% Process file with pro environments
  56.  
  57. Algebra:
  58.  
  59. \printlist{Algebra}
  60.  
  61. Geometry:
  62.  
  63. \printlist{Geometry}
  64.  
  65. Trigonometry:
  66.  
  67. \printlist{Trigonometry}
  68.  
  69. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement