
L
A
T
E
X Style
Didier Verna
Introduction
Coding Standards?
Not L
A
T
E
X ones?
What can we do?
Layout
Blanks
Names
Design
Duplication
Conditionals
Modularity
Behavior
Key/Value interfaces
Intercession
Social
Conclusion
Perspectives
Be modular
Write small macros
Veeeeeeeeeeery bad, splitbib, veeeeeeeeeeery bad!!
\ def \NM SB@w rite entr y# #1 ##2 ##3 ##4 ##5 ,{\ i f x \r ela x ## 5\ re l ax
\ el se
\ def \NMSB@c urrcat{## 1## 2# #3# #4}%
\ def \N MSB @cu rrc atl eve lon e{ ##1 ## 2}%
\ i f x \NM SB@ cur rca tle vel one \ NMSB@pr evca tle velo ne \ els e
\ expan da fte r \ i f x \csname NMSB titl e@ \ NMS B@c urr cat lev elo ne
\ endcsname \ r el ax
\ el se
\ i f@f il es w
\ expan da fte r \ l e t \e xpand af ter \NMSB@tempentry
\ csname NMSBtitl e@ \ NMS B@c urr cat lev elo ne \endcsname
\ ede f \ NMSB@tempentry { \ @ba cks las hchar s ub rub ri c { \ NMSB@tempentry }}
\ expan da fte r \ NMS B@write catbib \ exp an daf te r { \ NMSB@tempentry }
\ expan da fte r \ i f x \csname
NMSBcomment@\ NMS B@c urr cat lev elo ne \ endcsname \ r el ax
\ el se
\ immediate \w ri t e \ NMSB@catbib { \ str in g \vs ki p2ex^^ J%
\ str in g \hspace { −\ le ft m ar gi n } \ s tr i ng \re la x ^^ J%
\ str in g \be gin { mi ni pag e } { \ tex tw id th }^^ J%
\ str in g \ad dt ole ng th \ s tr i ng \p ar in de nt {2 0pt } ^^ J%
\ str in g \no ind ent }
\ expan da fte r \ l e t \e xpand af ter \NMSB@tempentry
\ csname NMSBcomment@ \ NMS B@c urr cat lev elo ne \ endcsname
\ expan da fte r \ NMS B@write catbib \ exp an daf te r {%
\ NMSB@tempentry^^ J }%
\ immediate \w ri t e \ NMSB@catbib { \ str in g \end{ minip age } ^^ J%
\ str in g \pa r \ st r in g \ addp ena lty {\ NMSB@penalty }
\ str in g \vs ki p2ex }
\ f i
\ f i
\ f i
\ xde f \ NMSB @pr evca tlevelo ne {# #1##2 }%
\ ifnum \ the SBr ese tde pth > 0\ re la x
\ se tco un te r { \ @ li stc t r } { 0 }%
\ f i
\ expan da fte r \ i f x \csname NMSBprefix@\ NMSB @pr evca tlevelo ne
\ endcsname \ r el ax
\ NM SB @c ur rp re fi xl eveloneto k { \ re l a x }%
\ el se
\ expan da fte r \ ex pa nda ft er \ expa nd aft er \N MS B@ currprefi xle vel one tok
\ expan da fte r \ ex pa nda ft er \ expa nd aft er {%
\ csname NMSBprefix@ \ NMSB @prevca tlev elo ne \endcsname}%
\ f i
\ f i
\ i f x \NMSB@currcat \ NMSB@prevcat \ els e
\ ifnum \ NMSB@currc at=999 9\ els e
\ expan da fte r \ i f x \csname NMSB titl e@ \NMSB@currca t\endcsname
\ re l ax
\ el se
\ i f@f il es w
\ immediate \w ri t e \ NMSB@catbib{%
\ str in g \pa r \ st r in g \ addp ena lty { −\ NMSB @halfpe nalt y }%
\ str in g \r el a x ^^ J%
\ str in g \it em []%
\ str in g \S Bs ub ti tl e }%
\ expan da fte r \ l e t \e xpand af ter \NMSB@tempentrya
\ csname NMSBtitl e@ \ NMS B@c urr cat lev elo ne \endcsname
\ expan da fte r \ l e t \e xpand af ter \NMSB@tempentryb
\ csname NMSBtitl e@ \NMSB@currcat\ endcsname
\ expan da fte r \ NMS B@write catbib \ exp an daf te r {%
\ expan da fte r { \ NMSB@tempentrya }}
\ expan da fte r \ NMS B@write catbib \ exp an daf te r {%
\ expan da fte r { \ NMSB@tempentryb }}
\ immediate \w ri t e \ NMSB@catbib { \ str in g \r el a x ^^ J%
\ str in g \pa r \ st r in g \ addp ena lty {\ NMSB@penalty }%
\ str in g \r el a x }%
\ expan da fte r \ i f x \csname
NMSBcomment@\ NMSB@currc at \endcsname \ re lax
\ el se
\ immediate \w ri t e \ NMSB@catbib { \ str in g \vs ki p2ex^^ J%
\ str in g \hspace { −\ le ft m ar gi n } \ s tr i ng \re la x ^^ J%
\ str in g \be gin { mi ni pag e } { \ tex tw id th }^^ J%
\ str in g \ad dt ole ng th \ s tr i ng \p ar in de nt {2 0pt } ^^ J%
\ str in g \no ind ent }
\ expan da fte r \ l e t \e xpand af ter \NMSB@tempentry
\ csname NMSBcomment@ \NMSB@currca t\endcsname
\ expan da fte r \ NMS B@write catbib \ exp an daf te r {%
\ NMSB@tempentry^^ J }%
\ immediate \w ri t e \ NMSB@catbib { \ str in g \end{ minip age } ^^ J%
\ str in g \pa r \ st r in g \ addp ena lty {\ NMSB@penalty }%
\ str in g \vs ki p2ex }
\ f i
\ f i
\ f i
\ f i
\ xde f \ NMSB@prevcat{# #1# #2# #3## 4}%
\ ifnum \ the SBr ese tde pth > 1\ re la x
\ se tco un te r { \ @ li stc t r } { 0 }%
\ f i
\ expan da fte r \ i f x \csname NMSBprefix@\NMSB@currcat\ endcsname\ r el ax
\ expan da fte r \ NM SB@ currpr efi xto k \ exp an da f te r {%
\ the \N MSB @cu rrp ref ix le ve lo ne to k }%
\ el se
\ expan da fte r \ ex pa nda ft er \ expa nd aft er \NM SB@cur rpr efi xto k
\ expan da fte r \ ex pa nda ft er \ expa nd aft er {%
\ csname NMSBprefix@ \ NMSB@currcat \ endcsname }
\ f i
\ f i
\ expan da fte r \ i f x \csname NMSBlabel@ ## 5\ endcsname \ r el a x
\ i f@f il es w
\ ste pc oun te r \ @ li stc t r
\ expan da fte r \ i f x \e xpand af ter \r e la x \ th e \ NM SB@ cu rrp refix tok
\ def \NMSB@tempentry { }%
\ el se
\ expan da fte r \ ex pa nda ft er \ expa nd aft er \de f
\ expan da fte r \ ex pa nda ft er \ expa nd aft er \NMSB@tempentry
\ expan da fte r \ ex pa nda ft er \ expa nd aft er {%
\ expan da fte r \ th e \ ex pan da fte r \ NM SB@ cur rpr efixt ok
\ the \v alu e { \ @ lis t ct r } }%
\ ede f \ NMSB@tempentry { [ \ NMSB@tempentry ]}
\ f i
\ ede f \ NMSB@tempentry{%
\ @ba cks las hcha r bi bi te m%
\ NMSB@tempentry { \ csname NMSBkey@## 5\ endcsname } }%
\ expan da fte r \ NMS B@write catbib \ exp an daf te r {%
\ NMSB@tempentry }
\ expan da fte r \ l e t \e xpand af ter \NMSB@tempentry
\ csname NMSBentry@# #5 \endcsname%
\ expan da fte r \ NMS B@write catbib \ exp an daf te r {%
\ NMSB@tempentry }
\ f i
\ setb ox \ @tempboxa= \hbox { \ th e \ NMSB@ cur rpr efi xtok \ the \va lu e { \ @ li stc t r } }%
\ if di m \ NM SB@ real lyl ong est < \wd \ @tempboxa
\ s et le ng th {\ N MSB @re allyl ong est } { \wd \ @tempboxa}%
\ xde f \ NM SB @r ea ll yl on gestlab el {%
\ expan da fte r \ i f x \e xpand af ter \r e la x \ th e \ NM SB@ cu rrp refix tok
\ el se \the \ NM SB@cu rrp refixt ok \ f i \ th e \ val ue {\ @ l is t c tr }} %
\ f i
\ el se
\ i f@f il es w
\ immediate \w ri t e \ NMSB@catbib{%
\ str in g \bibi te m }
\ expan da fte r \ l e t \e xpand af ter \NMSB@tempentry
\ csname NMSBlabel@ ## 5\ endcsname
\ expan da fte r \ NMS B@write catbib \ exp an daf te r {%
\ expan da fte r [ \ NMSB@tempentry ] }%
\ immediate \w ri t e \ NMSB@catbib{%
{ \csname NMSBkey@##5\endcsname } }%
\ expan da fte r \ l e t \e xpand af ter \NMSB@tempentry
\ csname NMSBentry@# #5 \endcsname%
\ expan da fte r \ NMS B@write catbib \ exp an daf te r {%
\ NMSB@tempentry^^ J^ ^J }
\ f i
\ setb ox \ @tempboxa= \hbox { \ csname NMSBlabel@ ##5 \endcsname}%
\ if di m \ NM SB@ real lyl ong est < \wd \ @tempboxa
\ s et le ng th {\ N MSB @re allyl ong est } { \wd \ @tempboxa}%
\ expan da fte r \ l e t \e xpand af ter \N MS B@ re al ly lo ngestla bel \ csname
NMSBlabel@# #5 \endcsname
\ f i
\ f i
\ f i
}
Originally 203 LoC. 156 after dead branches removal.
Only interested in the “green” lines. . .
25/37