The
gobble
Package
Martin Scharrer
martin@scharrer-scharrer.de
CTAN:
http://www.ctan.org/pkg/gobble
VC:
https://bitbucket.org/martin_scharrer/gobble
Version v0.2 – 2019/01/04
AbstractThegobbleLATEX package provides more macros to discard (gobble) macro
arguments. These macros are by default only for package and class writers, but are exported to the user level by thegobble-userpackage. The macros are also available as generic packages for other TEX formats.
1 Macros
1.1 Macros for Package/Class Writers
The following macros are provided by the genericgobble.texand the LATEX package
gobble. Some are already provided by the LATEX kernel. \@gobble
\@gobbletwo \@gobblethree \@gobblefour
Gobbles one, two, three or four mandatory arguments.
\@gobbleopt \@gobbletwoopt \@gobbleallopt
Gobbles one, two or all found optional arguments if present.
\@gobbletwoopttwo
\@firstofone
Reads one argument and expands to it, i.e. removes the braces around it.
\@firstoftwo
Reads two arguments and expands to the first one while discarding the second one.
\@secondoftwo
Reads two arguments and expands to the second one while discarding the first one.
\@firstofthree \@secondofthree \@thirdofthree
These macros read three arguments and expand to the first, second or third one, respectively, while discarding the other.
\@gobbletofi{〈code〉}〈discarded code〉\fi \@gobbletoelse{〈code〉}〈discarded code〉\else \@gobbletoor{〈code〉}〈discarded code〉\or
These macros read one argument and then gobble everything to the next\fi,\else
or\or, respectively. Afterwards they expand to the first argument. This allows to
break out of an\if.. or\ifcasebranch, which is sometimes required if code
should be executed after the conditional.
1.2 User Level Macros
The following macros are provided by the genericgobble-user.texand the LATEX
packagegobble-user. These also load thegobble.texfile or packagegobble
package, respectively.
They macros are identical to the corresponding versions with the leading ‘@’, but
can be used freely in a user document.
2 Implementation
1 % <! C O P Y R I G H T > 2 \ N e e d s T e X F o r m a t { L a T e X 2 e } [ 1 9 9 9 / 1 2 / 0 1 ] 3 \ P r o v i d e s P a c k a g e { g o b b l e }[% 4 % <! DATE > 5 % <! VERSION > 6 % <* DRIVER > 7 2 0 9 9 / 0 1 / 0 1 d e v e l o p 8 % </ DRIVER > 9 P r o v i d e s m o r e g o b b l e m a c r o s ] 10 \ i n p u t { g o b b l e } 11 % <! C O P Y R I G H T > 12 \ N e e d s T e X F o r m a t { L a T e X 2 e } [ 1 9 9 9 / 1 2 / 0 1 ] 13 \ P r o v i d e s P a c k a g e { gobble - u s e r }[% 14 % <! DATE > 15 % <! VERSION > 16 % <* DRIVER > 17 2 0 9 9 / 0 1 / 0 1 d e v e l o p 18 % </ DRIVER > 19 P r o v i d e s u s e r l e v e l m a c r o s ] 20 \ R e q u i r e P a c k a g e { g o b b l e } 21 \ i n p u t { gobble - u s e r } 22 \ e x p a n d a f t e r \ ifx \ c s n a m e g o b b l e . tex l o a d e d \ e n d c s n a m e \. r e l a x 23 \ e x p a n d a f t e r \ def \ c s n a m e g o b b l e . tex l o a d e d \. e n d c s n a m e {1}% 24 \ e l s e 25 \ e x p a n d a f t e r \ e n d i n p u t 26 \ fi \gobbletex@catcode 27 \ e x p a n d a f t e r \ e d e f \ c s n a m e g o b b l e t e x @ c a t c o d e \ e n d c s n a m e {. %28 \ catcode ‘\ n o e x p a n d \ @ =\ the \ catcode ‘\ @% 29 }%
\@secondoftwo 71 \ l o n g \ def \ @ f i r s t o f t w o # 1 # 2 { # 1 }% 72 \ l o n g \ def \ @ s e c o n d o f t w o # 1 # 2 { # 2 }% \@firstofthree \@secondofthree \@thirdofthree 73 \ l o n g \ def \ @ f i r s t o f t h r e e # 1 # 2 # 3 { # 1 }% 74 \ l o n g \ def \ @ s e c o n d o f t h r e e # 1 # 2 # 3 { # 2 }% 75 \ l o n g \ def \ @ t h i r d o f t h r e e # 1 # 2 # 3 { # 3 }% \@gobbletofi \@gobbletoelse \@gobbletoor 76 \ l o n g \ def \ @ g o b b l e t o f i # 1 # 2 \ fi {\ fi #1}% 77 \ l o n g \ def \ @ g o b b l e t o e l s e # 1 # 2 \ e l s e {\ e l s e #1}% 78 \ l o n g \ def \ @ g o b b l e t o o r # 1 # 2 \ or {\ or #1}% 79 \ g o b b l e t e x @ c a t c o d e
80 \ e x p a n d a f t e r \ ifx \ c s n a m e gobble - u s e r . tex l o a d e d \. e n d c s n a m e \ r e l a x
81 \ e x p a n d a f t e r \ def \ c s n a m e gobble - u s e r . tex l o a d e d \. e n d c s n a m e {1}%
82 \ e l s e
83 \ e x p a n d a f t e r \ e n d i n p u t 84 \ fi
\gobbletex@catcode
86 \ e x p a n d a f t e r \ e d e f \ c s n a m e g o b b l e t e x @ c a t c o d e \ e n d c s n a m e {.
%