l t ex3
play

L T EX3: A Creating the interface layer: xparse Code layer: - PowerPoint PPT Presentation

L A T EX3: Using the layers Frank Mittelbach & Joseph Wright Layers L T EX3: A Creating the interface layer: xparse Code layer: Using the layers expl3 Conclusions Its alright ma, its only witchcraft Frank Mittelbach


  1. L A T EX3: Using the layers Frank Mittelbach & Joseph Wright Layers L T EX3: A Creating the interface layer: xparse Code layer: Using the layers expl3 Conclusions It’s alright ma, it’s only witchcraft Frank Mittelbach & Joseph Wright 2013-10-24

  2. L A T EX3: Using the layers Frank Mittelbach & Joseph Wright Layers Creating the interface layer: xparse Code layer: expl3 Conclusions Himeji 2013

  3. Outline L A T EX3: Using the layers Layers 1 Frank Mittelbach & Joseph Wright Creating the interface layer: xparse 2 Layers Code layer: Creating the 3 interface layer: xparse Code layer: expl3 Conclusions

  4. L A T EX3 layers L A T EX3: Using the layers Frank Mittelbach & Joseph Wright Layers Creating the interface layer: xparse Code layer: expl3 Conclusions

  5. Layers of abstraction L A T EX3: Using the layers Frank Mittelbach & Joseph Wright Code Data structures and commands to build Layers higher-level typesetting elements Creating the interface layer: Functionality Typesetting elements that can be customized to xparse show varying behaviours Code layer: expl3 Design Specific elements and formatting from the Conclusions functionality layer User User level syntax to call instances

  6. The L A T EX 2 ε situation L A T EX3: Using the layers Frank Mittelbach & Joseph Wright User \section * [ � TOC � ] { � heading � } Layers Design Use of \@startsection : Creating the sets appearance of sections interface layer: xparse Code layer: Functionality Arguments of \@startsection : expl3 e.g. vertical space above below, etc. Conclusions Code \if@noskipsec \leavevmode \fi \addpenalty . . .

  7. The design layer Describing design L A T EX3: Using the layers Frank Mittelbach & Joseph Wright Ideally, document design could be written independent of code Layers Section headers will be set in 16 point sanserif, Creating the interface layer: with space before the section of 6 points and after of 6 xparse points unless immediately followed by a subsection in Code layer: expl3 which case . . . Conclusions Some ideas on this problem in xtemplate plus the ‘L A T EX data base’: these are difficult problems!

  8. The functionality layer L A T EX3: Using \def\@startsection#1#2#3#4#5#6{% the layers \if@noskipsec \leavevmode \fi Frank Mittelbach & \par Joseph Wright \@tempskipa #4\relax Layers \@afterindenttrue Creating the \ifdim \@tempskipa <\z@ interface layer: xparse \@tempskipa -\@tempskipa \@afterindentfalse Code layer: \fi expl3 Conclusions \if@nobreak \everypar{}% \else \addpenalty\@secpenalty\addvspace\@tempskipa \fi \@ifstar {\@ssect{#3}{#4}{#5}{#6}}% {\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}}}

  9. The code layer L A T EX3: Using Where do you find documentation for each of the following? the layers Which can you use in your own code? Frank Mittelbach & Joseph Wright \def\@float#1{% Layers \@ifnextchar[% Creating the {\@xfloat{#1}}% interface layer: {\edef\reserved@a xparse {\noexpand\@xfloat{#1}[\csname fps@#1\endcsname]}% Code layer: expl3 \reserved@a}} Conclusions \def\@dblfloat{% \if@twocolumn\let\reserved@a\@dbflt\else \let\reserved@a\@float\fi \reserved@a} \def\@xfloat #1[#2]{% \@nodocument \def \@captype {#1}% ...

  10. Outline L A T EX3: Using the layers Layers 1 Frank Mittelbach & Joseph Wright Creating the interface layer: xparse 2 Layers Code layer: Creating the 3 interface layer: xparse Code layer: expl3 Conclusions

  11. \newcommand in L A T EX 2 ε With a star . . . L A T EX3: Using the layers Frank Mittelbach & Joseph Wright \newcommand*{\foo}{Code with no arguments} Layers Creating the \newcommand*{\foo}[2]{Code using #1 and #2} interface layer: xparse Code layer: \newcommand*{\foo}[2][]{Code using #1 and #2} expl3 Conclusions \newcommand*{\foo}[2][default] {Code using #1 and #2}

  12. \newcommand in L A T EX 2 ε . . . or without L A T EX3: Using the layers Frank Mittelbach & Joseph Wright \newcommand {\foo}{Code with no arguments} Layers Creating the \newcommand {\foo}[2]{Code using #1 and #2} interface layer: xparse Code layer: \newcommand {\foo}[2][]{Code using #1 and #2} expl3 Conclusions \newcommand {\foo}[2][default] {Code using #1 and #2}

  13. The aims of xparse L A T EX3: Using the layers Frank Mittelbach & Joseph Wright Separate syntax from functionality Layers Define all arguments in one place Creating the interface layer: Intersperse mandatory and optional arguments xparse Code layer: More types of argument without code expl3 Mix long and short arguments Conclusions Create engine robust commands Informative error messages

  14. \...DocumentCommand L A T EX3: Using the layers Frank Mittelbach & Joseph Wright \NewDocumentCommand \RenewDocumentCommand Layers Creating the \ProvideDocumentCommand interface layer: xparse \DeclareDocumentCommand Code layer: expl3 Conclusions

  15. \...DocumentCommand L A T EX3: Using the layers Frank Mittelbach & Joseph Wright \NewDocumentCommand \RenewDocumentCommand Layers Creating the \ProvideDocumentCommand interface layer: xparse \DeclareDocumentCommand Code layer: expl3 Conclusions Syntax \DeclareDocumentCommand {\ � command � } { � arg. spec. � } { � code � }

  16. Mandatory arguments L A T EX3: Using the layers Frank Mittelbach & \DeclareDocumentCommand{\foo}{ } Joseph Wright {Code using no arguments} Layers Creating the \DeclareDocumentCommand{\foo}{ m } interface layer: xparse {Code using #1} Code layer: expl3 \DeclareDocumentCommand{\foo}{ m m } Conclusions {Code using #1 and #2} \DeclareDocumentCommand{\foo}{ m m m } {Code using #1, #2 and #3}

  17. Mandatory arguments Mixing short and long L A T EX3: Using the layers Frank Mittelbach & Joseph Wright \DeclareDocumentCommand{\foo}{ m m m } Layers {Three short arguments} Creating the interface layer: xparse \DeclareDocumentCommand{\foo}{ +m +m +m } Code layer: {Three long arguments} expl3 Conclusions \DeclareDocumentCommand{\foo}{ m +m m } {Only #2 is long}

  18. Optional arguments (Almost) like L A T EX 2 ε L A T EX3: Using the layers Frank Mittelbach & Joseph Wright Layers \DeclareDocumentCommand{\foo}{ O{} } Creating the interface layer: {One optional argument} xparse Code layer: expl3 \DeclareDocumentCommand{\foo}{ O{default} m } Conclusions {First argument optional with default value}

  19. Optional arguments Beyond L A T EX 2 ε L A T EX3: Using the layers Frank Mittelbach & Joseph Wright \DeclareDocumentCommand{\foo}{ O{} O{} m } Layers {Two optionals then a mandatory} Creating the interface layer: xparse \DeclareDocumentCommand{\foo}{ o m } Code layer: {% expl3 \IfNoValueTF{#1}% Conclusions {Code for just #2}% {Code for #1 and #2}% }

  20. Optional arguments Beyond L A T EX 2 ε L A T EX3: Using the layers Frank Mittelbach & Joseph Wright \newcommand*{\foo}[2][] Layers {Code here} Creating the interface layer: xparse \foo[\baz[arg1]]{arg2} Code layer: expl3 Conclusions #1 = \baz[arg1 #2 = ]

  21. Optional arguments Beyond L A T EX 2 ε L A T EX3: Using the layers Frank Mittelbach & Joseph Wright \DeclareDocumentCommand{\foo}{ O{} m } Layers {Code here} Creating the interface layer: xparse \foo[\baz[arg1]]{arg2} Code layer: expl3 Conclusions #1 = \baz[arg1] #2 = arg2

  22. Stars L A T EX3: Using the layers Frank Mittelbach & Joseph Wright Layers \DeclareDocumentCommand{\foo}{ s m } Creating the {% interface layer: xparse \IfBooleanTF {#1}% Code layer: {Process #2 with a star}% expl3 {Process #2 without a star}% Conclusions }

  23. Re-implementing \chapter The original L A T EX3: Using the layers Frank Mittelbach & Joseph Wright \def\chapter{...\secdef\@chapter\@schapter} Layers Creating the % syntax support code: interface layer: xparse Code layer: \def\secdef#1#2{\@ifstar{#2}{\@dblarg{#1}}} expl3 \def\@ifstar#1{\@ifnextchar *{\@firstoftwo{#1}}} Conclusions \long\def\@dblarg#1% {\kernel@ifnextchar[{#1}{\@xdblarg{#1}}} \long\def\@xdblarg#1#2{#1[{#2}]{#2}}

  24. Re-implementing \chapter In xparse L A T EX3: Using the layers Frank Mittelbach & \ExplSyntaxOn % So we don’t worry about spaces! Joseph Wright Layers \DeclareDocumentCommand { \chapter } { s o m } Creating the { interface layer: xparse \IfBooleanTF {#1} Code layer: { \@schapter {#3} } % ignore [..] if given expl3 { \IfNoValueTF {#2} Conclusions { \@chapter [#3] {#3} } % use title twice { \@chapter [#2] {#3} } % use [..] & title } }

  25. Other argument types L A T EX3: Using the layers Frank Mittelbach & Joseph Wright Layers d An optional argument delimited by two tokens Creating the interface layer: g An optional argument in braces (‘group’) xparse r A mandatory argument delimited by two tokens (‘required’) Code layer: expl3 t A single optional token Conclusions v An argument read verbatim

  26. Outline L A T EX3: Using the layers Layers 1 Frank Mittelbach & Joseph Wright Creating the interface layer: xparse 2 Layers Code layer: Creating the 3 interface layer: xparse Code layer: expl3 Conclusions

Recommend


More recommend