Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DeclareDocumentCommand{myMacro} {o o}
- {
- DeclareDocumentCommand{foo} {} {#1}
- DeclareDocumentCommand{bar} {} {#2}
- The foo argument was foo and the bar argument was bar
- }
- documentclass{article}
- usepackage{keyval,xparse}% http://ctan.org/pkg/{keyval,xparse}
- makeatletter
- % ========= KEY DEFINITIONS =========
- define@key{mymacro}{first}{defmm@first{#1}}
- define@key{mymacro}{second}{defmm@second{#1}}
- define@key{mymacro}{third}{defmm@third{#1}}
- define@key{mymacro}{last}{defmm@last{#1}}
- DeclareDocumentCommand{myMacro}{m}{%
- begingroup%
- % ========= KEY DEFAULTS + new ones =========
- setkeys{mymacro}{first={FIRST arg},second={SECOND arg},third={THIRD arg},last={LAST arg},#1}%
- First arg: mm@first par
- Second arg: mm@second par
- Third arg: mm@third par
- Last arg: mm@last
- endgroup%
- }
- makeatother
- begin{document}
- myMacro{last=LaSt,first=FiRsT} par hrulefill
- myMacro{} par hrulefill
- myMacro{third={$x^2$ textbf{stuff}},second={}}
- end{document}
- documentclass{article}
- usepackage{keyval,xparse,url}% http://ctan.org/pkg/{keyval,xparse,url}
- makeatletter
- % ========= KEY DEFINITIONS =========
- define@key{movie}{title}{expandafterdefcsname movietag @titleendcsname{#1}}
- define@key{movie}{releaseyear}{expandafterdefcsname movietag @releaseyearendcsname{#1}}
- define@key{movie}{genre}{expandafterdefcsname movietag @genreendcsname{#1}}
- define@key{movie}{url}{expandafterdefcsname movietag @urlendcsname{#1}}
- DeclareDocumentCommand{newMovie}{m m}{%
- % ========= KEY DEFAULTS + new ones =========
- defmovietag{#1}% Store movie tag (used when setting/storing keys)
- setkeys{movie}{title={},releaseyear={},genre={},url={},#2}% Create keys
- }
- DeclareDocumentCommand{showMovie}{m}{%
- textbf{csname #1@titleendcsname} (csname #1@releaseyearendcsname),
- textit{csname #1@genreendcsname},
- expandafterexpandafterexpandafterurlexpandafterexpandafterexpandafter{csname #1@urlendcsname}.
- }
- makeatother
- begin{document}
- % Movie declarations
- newMovie{anchorman2}{
- url={http://www.imdb.com/title/tt1229340/},
- releaseyear=2013,
- title={Anchorman: The Legend Continues},
- genre=Comedy}
- newMovie{lego}{
- title={The Lego Movie},
- releaseyear=2014,
- url={http://www.imdb.com/title/tt1490017/},
- genre={Animation, Action, Comedy}}
- newMovie{magic}{
- title={Now You See Me},
- url={http://www.imdb.com/title/tt1670345/},
- releaseyear=2013,
- genre={Crime, Thriller}}
- % Show movie details
- showMovie{magic}
- showMovie{anchorman2}
- showMovie{lego}
- end{document}
- documentclass{article}
- usepackage{xparse,url}
- ExplSyntaxOn
- % keys
- keys_define:nn { oxinabox/movies }
- {
- title .tl_set:N = l_oxinabox_title_tl,
- releaseyear .tl_set:N = l_oxinabox_releaseyear_tl,
- genre .tl_set:N = l_oxinabox_genre_tl,
- url .tl_set:N = l_oxinabox_url_tl,
- }
- % user level commands
- NewDocumentCommand{newMovie}{m m}
- {
- oxinabox_newmovie:nn { #1 } { #2 }
- }
- NewDocumentCommand{showMovie}{m}
- {
- oxinabox_showmovie:n { #1 }
- }
- % internal functions
- cs_new_protected:Npn oxinabox_newmovie:nn #1 #2
- {
- group_begin: % keep the assignment to the keys local
- prop_new:c { g_oxinabox_movie_#1_prop }
- keys_set:nn { oxinabox/movies } { #2 }
- prop_gput:cnV { g_oxinabox_movie_#1_prop } { title } l_oxinabox_title_tl
- prop_gput:cnV { g_oxinabox_movie_#1_prop } { releaseyear } l_oxinabox_releaseyear_tl
- prop_gput:cnV { g_oxinabox_movie_#1_prop } { genre } l_oxinabox_genre_tl
- prop_gput:cnV { g_oxinabox_movie_#1_prop } { url } l_oxinabox_url_tl
- group_end:
- }
- cs_new:Npn oxinabox_getvalue:nn #1 #2
- {
- prop_item:cn { g_oxinabox_movie_#1_prop } { #2 }
- }
- cs_new_protected:Npn oxinabox_showmovie:n #1
- {
- parnoindent
- textbf{ oxinabox_getvalue:nn { #1 } { title } }, ~ %
- textbf{ oxinabox_getvalue:nn { #1 } { releaseyear } }, ~ %
- textbf{ oxinabox_getvalue:nn { #1 } { genre } },
- \
- use:x { exp_not:N url { oxinabox_getvalue:nn { #1 } { url } } }
- }
- ExplSyntaxOff
- begin{document}
- % Movie declarations
- newMovie{anchorman2}{
- url={http://www.imdb.com/title/tt1229340/},
- releaseyear=2013,
- title={Anchorman: The Legend Continues},
- genre=Comedy}
- newMovie{lego}{
- title={The Lego Movie},
- releaseyear=2014,
- url={http://www.imdb.com/title/tt1490017/},
- genre={Animation, Action, Comedy}}
- newMovie{magic}{
- title={Now You See Me},
- url={http://www.imdb.com/title/tt1670345/},
- releaseyear=2013,
- genre={Crime, Thriller}}
- % Show movie details
- showMovie{magic}
- showMovie{anchorman2}
- showMovie{lego}
- end{document}
Add Comment
Please, Sign In to add comment