Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % lurc.tex
- % LaTeX Utility/Template for Generic Reusable Code (LURC)
- % Usage:
- %
- % In main .tex file:
- %
- % \InsertModule{mypath/foo}{instance-A}[key1=somevalue1,key2=somevalue2]
- %
- % \InsertModule{mypath/foo}{instance-B}
- %
- % \InsertModule{mypath/foo}{instance-C}[some other key=some value]
- %
- %
- % In mypath/foo.tex (included .tex file):
- %
- % \Instance
- %
- % \OneTimeOnly{
- % only once code
- % \GetKeyValue{key1}
- % \GetKeyValue{key2}
- % }
- %
- % every time code
- %
- % \OnlyFor{instance-A}{
- % 'instance-A' code.
- % }
- %
- % \OnlyFor{instance-B,instance-C}{
- % \GetKeyValue{some other key}
- % 'instance-B' or 'instance-C' code
- % }
- \makeatletter
- \usepackage{pgfkeys}
- \pgfkeys{/generic-reusable/.unknown/.code={%
- \expandafter\edef\csname gr-arg-\pgfkeyscurrentkey\endcsname{\unexpanded\expandafter{\pgfkeyscurrentvalue}}%
- }}
- \def\gr@markincluded#1{\global\expandafter\let\csname gr-file-#1-alreadyincluded\endcsname\empty}
- \def\gr@ifincluded#1{\@ifundefined{gr-file-#1-alreadyincluded}}
- \def\gr@OneTimeOnly{%
- \gr@ifincluded{\gr@filename}%
- {\@firstofone}%
- {\@gobble}%
- }
- \def\gr@OnlyFor#1{%
- \gr@OnlyFor@#1,\gr@nil
- }
- \def\gr@OnlyFor@#1,{%
- \def\gr@temp{#1}%
- \def\next{\@ifnextchar\gr@nil{\@gobbletwo}{\gr@OnlyFor@}}%
- \ifx\gr@temp\gr@requestedinstance
- \let\next\gr@OnlyFor@dobody
- \fi
- \next
- }
- \def\gr@GetKeyValue#1{\csname gr-arg-/generic-reusable/#1\endcsname}
- \def\gr@OnlyFor@dobody#1\gr@nil#2{#2}
- \def\InsertModule#1#2{%
- \@ifnextchar[{\gr@InsertModule@{#1}{#2}}{\gr@InsertModule@{#1}{#2}[]}%
- }
- \def\gr@InsertModule@#1#2[#3]{%
- \begingroup
- \let\OneTimeOnly\gr@OneTimeOnly
- \let\OnlyFor\gr@OnlyFor
- \let\GetKeyValue\gr@GetKeyValue
- \pgfqkeys{/generic-reusable}{#3}
- \def\gr@requestedinstance{#2}%
- \let\Instance\gr@requestedinstance
- \def\gr@filename{#1}%
- \input #1 \relax
- \endgroup
- \gr@markincluded{#1}
- }
- \makeatother
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement