.net c# pdf viewer : Combine pdf application Library utility html .net asp.net visual studio letterfaq24-part539

• definesthemacrofortheextracode;and
• pointsthetoken
\everypar
atthenewtokenregister.
andawaywego.
Theform
\mypkg@...
is(sortof)blessedforLaTeXpackageinternalnames,which
iswhythisexampleusesmacrosofthatform.
346 Isthiscommanddefined?
MacrosetsfromtheearliestdaysofTeXprogrammingmaybeobservedtotestwhether
commandsexistbyusing
\ifx\command\undefined
hstuffi...
(whichofcourseactuallyteststhatthecommanddoesn’texist).LaTeXprogrammers
canmakeuseoftheinternalcommand
\@ifundefined{cmd name}{action1}{action2}
whichexecutes
action1
ifthecommandisundefined,and
action2
ifitisdefined(cmd
nameisthecommandnameonly,omittingthe‘
\
’character).
The
\@ifundefined
commandisbasedonthesequence
\expandafter \ifx \csname cmd d name\endcsname e \relax
whichreliesontheway
\csname
works:ifthecommanddoesn’texist,itsimplycreates
itasanaliasfor
\relax
.
So:whatiswrongwiththesetechniques?
Using
\undefined
blithelyassumesthatthecommandisindeednotdefined.This
isn’tentirelysafe;onecouldmakethenamemoreimprobable,butthatmaysimply
makeitmoredifficulttospotaproblemwhenthingsgowrong.LaTeXprogrammers
whousethetechniquewilltypicallyemploy
\@undefined
,addingasinglelevelof
obscurity.
The
\@ifundefined
mechanismhastheunfortunatepropertyofpollutingthename
space:eachtestthatturnsoutundefinedaddsanametothesetTeXisholding,and
oftenallthose“
\relax
”namesservenopurposewhatever.Evenso(sadly)thereare
placesinthecodeofLaTeXwheretheexistenceofthe
\relax
isreliedupon,afterthe
test,sowecan’tgetawayfrom
\@ifundefined
altogether.
DavidKastrupoffersthe(rathertricky)
{\expandafter}\expandafter\ifx \csname cmd d name\endcsname\relax ...
which“creates”the
\relax
-commandinsidethegroupofthefirst
\expandafter
,
thereforeforgetsitagainoncethetestisdone.Thetestisaboutasgoodasyoucando
withmacros.
Thee-TeXsystemsystemcomestoourhelphere:itdefinestwonewprimitives:
\ifdefined
,whichtestswhetherathingisdefined(thenegativeofcomparing
with
\undefined
,asitwere),and
\ifcsnamecmd name\endcsname
,whichdoesthenegativeof
\@ifundefined
withoutthe
\relax
-commandside-effect.
So,inane-TeX-basedsystem,thefollowingtwoconditionalclausesdothesamething:
\ifdefined\foo
\message{\string\foo\space is s defined}%
\else
\message{no command \string\foo}%
\fi
%
\ifcsname foo\endcsname
\message{\string\foo\space is s defined}%
\else
\message{no command \string\foo}%
\fi
241
Combine pdf - Merge, append PDF files in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
Provide C# Demo Codes for Merging and Appending PDF Document
pdf combine files online; combine pdf online
Combine pdf - VB.NET PDF File Merge Library: Merge, append PDF files in vb.net, ASP.NET, MVC, Ajax, WinForms, WPF
VB.NET Guide and Sample Codes to Merge PDF Documents in .NET Project
merge pdf files; best pdf merger
However,afterusingtheLaTeX
\@ifundefined{foo}
...,theconditionalswilldetect
thecommandas“existing”(sinceithasbeen
\let
to
\relax
);soitisimportantnotto
mixmechanismsfordetectingthestateofacommand.
Sincemostdistributionsnowadaysusee-TeXastheirbaseexecutableformost
packages,thesetwoprimitivesmaybeexpectedappearwidelyinnewmacropackages.
R.2 LaTeXmacrotoolsandtechniques
347 UsingPlainorprimitivecommandsinLaTeX
It’swell-knownthatLaTeXcommandstendtobemorecomplex,andtorunmoreslowly
than,anyPlainTeX(orprimitive)commandthattheyreplace.Thereisthereforegreat
temptationnottouseLaTeXcommandswhenmacroprogramming.Nevertheless,the
generalruleisthatyoushoulduseLaTeXcommands,ifthereareseemingequivalents.
Theexceptioniswhenyouaresureyouknowthedifferencesbetweenthetwocommands
andyouknowthatyouneedthePlainTeXversion.So,forexample,use
\mbox
inplace
of
\hbox
unlessyouknowthattheextrasthatLaTeXprovidesin
\mbox
wouldcause
troubleinyourapplication.Similarly,use
\newcommand
(oroneofitsrelatives)unless
youneedoneoftheconstructsthatcannotbeachievedwithouttheuseof
\def
(or
friends).
Asageneralrule,anyLaTeXtextcommandwillstartanewparagraphifnecessary;
thisisn’tthecasewithPlainTeXcommands,afactwhichhasapotentialtoconfuse.
Thecommands
\smallskip
,
\medskip
and
\bigskip
existbothinPlainTeX
andLaTeX,butbehaveslightlydifferently:inPlainTeXtheyterminatethecurrent
paragraph,butinLaTeXtheydon’t. Thecommand
\line
ispartofpicturemode
inLaTeX,whereasit’sdefinedas“
\hbox to o \hsize
”inPlainTeX.(There’sno
equivalentforusersofthePlainTeXcommandinLaTeX:anequivalentappearsasthe
internalcommand
\@@line
).
MathssettingshowsacasewheretheLaTeXversionisessentiallyequivalentto
theTeXprimitivecommands:theLaTeX
\( ... . \)
doesessentiallynodifferentto
theprimitive
$ ... . $
;exceptforcheckingthatyou’renotattemptingtoopenamaths
environmentwhenyou’realreadyinone,orattemptingtocloseonewhenyou’renot.
However,
\[ ... \]
hasamoresignificantdifferencefrom
$$ ... $$
:theprimitive
version,usedinLaTeX,canmisstheeffectoftheclassoption
fleqn
.
Fonthandlingis,ofcourse,wildlydifferentinPlainTeXandLaTeX.PlainTeX’s
fontloadingcommand(
\font\foo=
hfontnamei)anditsLaTeXequivalent(
\newfont
)
shouldbeavoidedwhereverpossible.Theyareonlysafeinthemosttrivialcontexts,
andarepotentialsourcesofgreatconfusioninmanycircumstances.Furtherdiscussion
ofthisissuemaybefoundin“What’swrongwith
\newfont
?”.
348
\@
and
@
inmacronames
Macronamescontaining
@
areinternaltoLaTeX,andwithoutspecialtreatmentjust
don’tworkinordinaryuse.Aniceexampleoftheproblemscausedisdiscussedin
\@
inverticalmode”.
Theproblemsusersseearecausedbycopyingbitsofaclass(
.cls
file)orpackage
(
.sty
file)intoadocument,orbyincludingaclassorpackagefile intoaLaTeX
documentbysomemeansotherthan
\documentclass
or
\usepackage
.LaTeXdefines
internalcommandswhosenamescontainthecharacter
@
toavoidclashesbetweenits
internalnamesandnamesthatwewouldnormallyuseinourdocuments.Inorderthat
thesecommandsmayworkatall,
\documentclass
and
\usepackage
playaround
withthemeaningof
@
.
Ifyou’veincludedafilesomeotherway(forexample,using
\input
),youcan
probablysolvetheproblembyusingthecorrectcommand.
Ifyou’reusingafragmentofapackageorclass,youmaywellfeelconfused:books
suchasthefirsteditionoftheTheLaTeXCompanionarefulloffragmentsofpackages
asexamplesforyoutoemploy.ThesecondeditionoftheCompanionmakesclearer
howyoushouldusethesefragments,andinaddition,thecodeofalltheexamplesis
nowavailableonCTAN.Toseethetechniqueinpractice,lookattheexamplebelow,
fromfile
2-2-7.ltx
intheCompanionexamplesdirectory:
242
Online Merge PDF files. Best free online merge PDF tool.
RasterEdge C#.NET PDF document merging toolkit (XDoc.PDF) is designed to help .NET developers combine PDF document files created by different users to one PDF
c# merge pdf files into one; batch merge pdf
C# PDF: C#.NET PDF Document Merging & Splitting Control SDK
PDF Merging & Splitting Application. This C#.NET PDF document merger & splitter control toolkit is designed to help .NET developers combine PDF document files
add pdf together one file; pdf merge comments
\makeatletter
\renewcommand\subsection{\@startsection
{subsection}{2}{0mm}%name, level, , indent
{-\baselineskip}%
beforeskip
{0.5\baselineskip}%
afterskip
{\normalfont\normalsize\itshape}}% style
\makeatother
(Thatexampleappearsonpage29ofTheLaTeXCompanion,secondedition.)
Thealternativeistotreatallthesefragmentsasapackageproper,bundlingthem
upintoa
.sty
fileandincludingthemwith
\usepackage
;thiswayyouhideyour
LaTeXinternalcodesomewherethatLaTeXinternalcodeisexpected,whichoften
looks‘tidier’.
ExamplesfromtheCompanion:
info/examples/tlc2
349 What’sthereasonfor‘protection’?
SometimesLaTeXsavesdataitwillrereadlater.Thesedataareoftentheargumentof
somecommand;theyaretheso-calledmovingarguments.(‘Moving’becausedataare
movedaround.)Candidatesareallargumentsthatmaygointotableofcontents,listof
figures,etc.;namely,datathatarewrittentoanauxiliaryfileandreadinlater.Other
placesarethosedatathatmightappearinhead-orfootlines.Sectionheadingsandfigure
captionsarethemostprominentexamples;there’sacompletelistinLamport’sbook
(seeTeX-relatedbooks).
What’sgoingonreally,behindthescenes?Thecommandsinmovingargumentsare
normallyexpandedtotheirinternalstructureduringtheprocessofsaving.Sometimes
thisexpansionresultsininvalidTeXcode,whichshowseitherduringexpansionor
whenthecodeisprocessedagain.Protectingacommand,using“
\protect\cmd
”tells
LaTeXtosave
\cmd
as
\cmd
,withoutexpandingitatall.
So,whatisa‘fragilecommand’?—it’sacommandthatexpandsintoillegalTeX
codeduringthesaveprocess.
Whatisa‘robustcommand’?—it’sacommandthatexpandsintolegalTeXcode
duringthesaveprocess.
Lamport’sbooksaysinitsdescriptionofeveryLaTeXcommandwhetheritis
‘robust’or‘fragile’;italsosaysthateverycommandwithanoptionalargumentis
fragile.Thelistisn’treliable,andneitheristheassertionaboutoptionalarguments;
thestatementsmayhavebeentrueinearlyversionsofLaTeX2ebutarenotanylonger
necessarilyso:
• Somefragilecommands,suchas
\cite
,havebeenmaderobustinlaterrevisions
ofLaTeX.
• Somecommands,suchas
\end
and
\nocite
,arefragileeventhoughtheyhaveno
optionalarguments.
• The “user’sway” of f creating a a command withan optional argument (using
\newcommand
or
\newcommand
*
)nowalwayscreatesarobustcommand(though
macroswithoutoptionalargumentsmaystillbefragileiftheydothingsthatare
themselvesfragile).
• Thereisnoreasonthatapackageauthorshouldnotalsomakerobustcommands
withoptionalargumentsaspartofthepackage.
• Somerobustcommandsareredefinedbycertainpackagestobefragile(the
\cite
commandcommonlysuffersthistreatment).
Further,simply“hiding”afragilecommandinanothercommand,hasnoeffecton
fragility.So,if
\fred
isfragile,andyouwrite:
\newcommand{\jim}{\fred}
then
\jim
isfragiletoo.Thereis,however,the
\newcommand
-replacement
\DeclareRobustCommand
,
whichalwayscreatesarobustcommand(whetherornotithasoptionalarguments).The
syntaxof
\DeclareRobustCommand
issubstantiallyidenticaltothatof
\newcommand
,
andifyoudothewrappingtrickaboveas:
243
VB.NET PDF: Use VB.NET Code to Merge and Split PDF Documents
Combine End Sub Private Sub Combine(source As List(Of [String]), destn As [String]) Implements PDFDocument.Combine End Sub. APIs for Splitting PDF document in
batch pdf merger online; attach pdf to mail merge
C# PowerPoint - Merge PowerPoint Documents in C#.NET
Combine and Merge Multiple PowerPoint Files into One Using C#. This part illustrates how to combine three PowerPoint files into a new file in C# application.
pdf mail merge plug in; pdf combine pages
\DeclareRobustCommand{\jim}{\fred}
then
\jim
isrobust.
Finally,wehavethemakerobustpackage,whichdefines
\MakeRobustCommand
to
convertacommandtoberobust.Withthepackage,the“wrapping”abovecansimply
bereplacedby:
\MakeRobustCommand\fred
Whereafter,
\fred
isrobust.Usingthepackagemaybereasonableifyouhavelotsof
fragilecommandsthatyouneedtouseinmovingarguments.
Inshort,thesituationisconfusing.No-onebelievesthisissatisfactory;theLaTeX
teamhaveremovedtheneedforprotectionofsomethings,butthetechniquesavailable
incurrentLaTeXmeanthatthisisanexpensiveexercise.Itremainsalong-termaimof
theteamtoremoveallneedfor
\protect
ion.
makerobust.sty
DistributedaspartofHeikoOberdiek’sbundle
macros/latex/contrib/oberdiek
350
\edef
doesnotworkwith
\protect
RobustLaTeXcommandsareeither“naturallyrobust”—meaningthattheynever
need
\protect
,or“self-protected”—meaningthattheyhave
\protect
builtinto
theirdefinitioninsomeway. Self-protectedcommands,andfragilecommandswith
\protect
ionareonlyrobustinacontextwherethe
\protect
mechanismisproperly
handled. Thebodyofan
\edef
definitiondoesn’thandle
\protect
properly,since
\edef
isaTeXprimitiveratherthanaLaTeXcommand.
ThisproblemisresolvedbyaLaTeXinternalcommand
\protected@edef
,which
doesthejobof
\edef
whilekeepingthe
\protect
mechanismworking. There’sa
corresponding
\protected@xdef
whichdoesthejobof
\xdef
.
Ofcourse,thesecommandsneedtobetendedcarefully,sincethey’reinternal:see
’@’incontrolsequencenames.
351 ThedefinitionsofLaTeXcommands
ThereareseveralreasonstowanttoknowthedefinitionsofLaTeXcommands:from
thesimplest“idlecuriosity”,tothepressingneedtopatchsomethingtomakeit“work
thewayyouwantit”.Noneofthesearepuremotives,butknowledgeandexpertise
seldomarrivethroughthepurestofmotives.
UsingaTeXexecutableofsomesort,thesimpleansweristotry
\show
,inarun
thatistakingcommandsfromtheterminal:
*
\makeatletter
*
\show\protected@edef
> \protected@edef=macro:
->\let \@@protect t \protect
\let \protect \@unexpandable@protect
\afterassignment \restore@protect t \edef f .
(I’verearrangedtheoutputthere,fromtheratherconfusedversionTeXitselfproduces.)
So,whatabout
\@unexpandable@protect
?:
*
\show\@unexpandable@protect
> \@unexpandable@protect=macro:
->\noexpand \protect \noexpand d .
andwe’restartingtoseehowonepartofthe
\protect
ionmechanismworks(onecan
probablyfairlysafelyguesswhat
\restore@protect
does).
Manykernelcommandsaredeclaredrobust:
*
\show\texttt
> \texttt=macro:
->\protect \texttt
.
244
C# Word - Merge Word Documents in C#.NET
Combine and Merge Multiple Word Files into One Using C#. This part illustrates how to combine three Word files into a new file in C# application.
pdf combine; combine pdf
C# PDF File Split Library: Split, seperate PDF into multiple files
Split PDF document by PDF bookmark and outlines. Also able to combine generated split PDF document files with other PDF files to form a new PDF file.
reader merge pdf; pdf merge
sothat
\show
isn’tmuchhelp.Defineacommand
\pshow
asshownbelow,andsimply
executethecommandtofinditsdefinition:
*
\def\pshow#1{{\let\protect\show #1}}
*
\pshow\texttt
> \texttt =\long g macro:
#1->\ifmmode \nfss@text t {\ttfamily y #1}%
\else \hmode@bgroup \text@command {#1}%
\ttfamily \check@icl l #1\check@icr
\expandafter \egroup p \fi .
Notethatthecommandnamethatisprotectedisthe‘base’command,withaspace
appended.Thisiscrypticallyvisible,inacoupleofplacesabove.(Again,theoutput
hasbeensanitised.)
Thecommandtexdef(orlatexdef—thesamecommandwithadifferentname)will
doallthatforyouandreturntheresultsslightlymoretidilythanLaTeXitselfmanages.
Forexample:
$ latexdef texttt
gives:
macro:->\protect \texttt
\texttt :
#1->\ifmmode \nfss@text t {\ttfamily y #1}%
\else \hmode@bgroup \text@command {#1}%
\ttfamily \check@icl l #1\check@icr
\expandafter \egroup p \fi .
(again,theoutputhasbeensanitised—butweseethatlatexdefhasuseful‘intelligence’
init,asithasspottedanddealtwiththe
\protect
.)
Withthe
-s
switch,latexdefwillgiveyouasourcelocation:
$ latexdef -s s texttt
% latex.ltx, , line 3736:
\DeclareTextFontCommand{\texttt}{\ttfamily}
thoughoneshouldnotethatitdoesn’tgiveyouthedetailoftheactualcoding,merely
thedefinition’slocation.
Environmentsalsosurrendertheirdetailstolatexdef:
$ latexdef -E E itemize
\itemize:
macro:->\ifnum \@itemdepth h >\thr@@ \@toodeep
\else \advance \@itemdepth h \@ne
\edef \@itemitem {labelitem\romannumeral l \the e \@itemdepth}%
\expandafter \list \csname \@itemitem m \endcsname
{\def \makelabel l ##1{\hss \llap p {##1}}}%
\fi
\enditemize:
macro:->\global \advance \@listdepth \m@ne \endtrivlist
(Yetagain,thisisasanitisedversionofthemacrodefinitionoutput,whichappearsasa
singleverywidelineforeachdefinition.)
Ifonehasamalleabletexteditor,thesameinvestigationmaybeconductedby
examiningthefile
latex.ltx
(whichisusuallytobefound,inaTDSsystem,in
directory
tex/latex/base
).
245
VB.NET TIFF: Merge and Split TIFF Documents with RasterEdge .NET
filePath As [String], docList As [String]()) TIFFDocument.Combine(filePath, docList) End to provide powerful & profession imaging controls, PDF document, tiff
pdf mail merge; merge pdf online
VB.NET PowerPoint: Merge and Split PowerPoint Document(s) with PPT
Just like we need to combine PPT files, sometimes, we also want to separate a Note: If you want to see more PDF processing functions in VB.NET, please follow
acrobat split pdf into multiple files; best pdf merger
Infact,
latex.ltx
istheproductofadocstripprocessona large numberof
.dtx
files,andyoucanrefertothoseinstead.TheLaTeXdistributionincludesafile
source2e.tex
,andmostsystemsretainit,againin
tex/latex/base
.
Source2e.tex
maybeprocessedtoprovideacompletesourcelistingoftheLaTeXkernel(infactthe
processisn’tentirelystraightforward,butthefileproducesmessagesadvisingyouwhat
todo).Theresultisahugedocument,withaline-numberindexofcontrolsequences
theentirekernelandaseparateindexofchangesrecordedineachofthefilessincethe
LaTeXteamtookover.
Theprintedkernelisanicethingtohave,butit’sunwieldyandsitsonmyshelves,
seldomused. Oneproblemisthatthecommentsarepatchy: thedifferentmodules
rangefromwellandlucidlydocumented,throughmodulesdocumentedonlythrough
anautomaticprocessthatconvertedthedocumentationofthesourceofLaTeX2.09,to
modulesthathardlyhadanyusefuldocumentationevenintheLaTeX2.09original.
Infact,eachkernelmodule
.dtx
filewillprocessseparatelythroughLaTeX,so
youdon’thavetoworkwiththewholeof
source2e
.Youcaneasilydeterminewhich
moduledefinesthemacroyou’reinterestedin:useyour“malleabletexteditor”tofind
thedefinitionin
latex.ltx
;thensearchbackwardsfromthatpointforalinethatstarts
%%% From m File:
—thatlinetellsyouwhich
.dtx
filecontainsthedefinitionyouare
interestedin.Doingthisfor
\protected@edef
,wefind:
%%% From File: : ltdefns.dtx
Whenwecometolookatit,
ltdefns.dtx
provestocontainquiteadissertationon
themethodsofhandling
\protect
ion;italsocontainssomeautomatically-converted
LaTeX2.09documentation.
Andofcourse,thekernelisn’tallofLaTeX:yourcommandmaybedefinedinoneof
LaTeX’sclassorpackagefiles.Forexample,wefindadefinitionof
\thebibliography
inarticle,butthere’sno
article.dtx
.Somesuchfilesaregeneratedfrompartsofthe
kernel,somefromotherfilesinthedistribution.Youfindwhichbylookingatthestart
ofthefile:in
article.cls
,wefind:
%% This s is s file ‘article.cls’,
%% generated d with the docstrip utility.
%%
%% The original source e files s were:
%%
%% classes.dtx
(with options: ‘article’)
soweneedtoformat
classes.dtx
toseethedefinitionincontext.
Allthese.dtxfilesareonCTANaspartofthemainLaTeXdistribution.
LaTeXdistribution:
macros/latex/base
texdef,
akalatexdef:
support/texdef
352 Optionalargumentslike
\section
Optionalarguments,inmacrosdefinedusing
\newcommand
,don’tquiteworklikethe
optionalargumentto
\section
.Thedefaultvalueof
\section
’soptionalargumentis
thevalueofthemandatoryargument,but
\newcommand
requiresthatyou‘know’the
valueofthedefaultbeforehand.
Therequisitetrickistouseamacrointheoptionalargument:
\documentclass{article}
\newcommand\thing[2][\DefaultOpt]{%
\def\DefaultOpt{#2}%
optional arg: #1,
mandatory arg: #2%
}
\begin{document}
\thing{manda}% #1=#2
\thing[opti]{manda}% #1="opti"
\end{document}
246
LaTeXitselfhasatrickier(butlessreadilyunderstandable)method,usingamacro
\@dblarg
;insideLaTeX,theexampleabovewouldhavebeenprogrammed:
\newcommand\thing{\@dblarg\@thing}
\newcommand\@thing[2][\@error]{%
optional arg: #1,
mandatory arg: #2%
}
Inthatcode,
\@thing
isonlyevercalledwithanoptionalandamandatoryargument;if
thedefaultfromthe
\newcommand
isinvoked,abuginusercodehasbitten...
353 Morethanoneoptionalargument
Ifyou’vealreadyread“breakingthe9-argumentlimit”.youcanprobablyguessthe
“simple”solutiontothisproblem:commandrelaying.
LaTeXallowscommandswithasingleoptionalargumentthus:
\newcommand{\blah}[1][Default]{...}
Youmaylegallycallsuchacommandeitherwithitsoptionalargumentpresent,as
\blah[nonDefault]
orwithout,as
\blah
;inthelattercase,thecodeof
\blah
will
haveanargumentof
Default
.
Todefineacommandwithtwooptionalarguments,weusetherelayingtechnique,
asfollows:
\newcommand{\blah}[1][Default1]{%
\def\ArgI{{#1}}%
\BlahRelay
}
\newcommand\BlahRelay[1][Default2]{%
% the first optional argument is now in
% \ArgI
% the second d is s in n #1
...%
}
Ofcourse,
\BlahRelay
mayhaveasmanymandatoryargumentsasareallowed,after
allowancefortheonetakenupwithitsownoptionalargument—thatis,8.
Variantsof
\newcommand
(andfriends),withnameslike
\newcommandtwoopt
,are
availableinthetwooptpackage.However,ifyoucan,it’sprobablybettertolearnto
writethecommandsyourself,justtoseewhythey’renotevenagoodideafromthe
programmingpointofview.
Acommandwithtwooptionalargumentsstrainsthelimitofwhat’ssensible:ob-
viouslyyoucanextendthetechniquetoprovideasmanyoptionalargumentsasyour
feveredimaginationcansummon.However,seethecommentsontheuseofthekeyval
package,in“breakingthe9-argumentlimit”,whichoffersanalternativewayforward.
Ifyoumust,however,considertheoptparamsorxargspackages. Optparams
providesa
\optparams
commandthatyouuseasanintermediateindefiningcommands
withuptonineoptionalarguments.Thedocumentationshowsexamplesofcommands
withfouroptionalarguments(andthisfromanauthorwhohashisownkey-value
package!).
Thexargspackageusesakey-valuepackage(xkeyval)todefinethelayoutofthe
optionalarguments.Thus
\usepackage{xargs}
...
\newcommandx{\foo}[3][1=1, 3=n]{...}
definesacommand
\foo
thathasanoptionalfirstargument(default1),amandatory
secondargument,andanoptionalthirdargument(defaultn).
AnalternativeapproachisofferedbyScottPakin’snewcommandprogram,which
takesacommandnameandadefinitionofasetofcommandarguments(inafairly
247
readily-understoodlanguage),andemits(La)TeXmacroswhichenablethecommandto
bedefined.ThecommandrequiresthataPythoninterpreter(etc.)beinstalledonyour
computer.
newcommand.py
:
support/newcommand
optparams.sty
: Distributedaspartof
macros/latex/contrib/sauerj
twoopt.sty
: Distributedaspartof
macros/latex/contrib/oberdiek
xargs.sty
:
macros/latex/contrib/xargs
xkeyval.sty
:
macros/latex/contrib/xkeyval
354 Commandsdefinedwith*options
LaTeXcommandscommonlyhave“versions”definedwithanasterisktaggedonto
theirname:forexample
\newcommand
and
\newcommand
*
(theformerdefinesa
\long
versionofthecommand).
Thesimple-mindedwayforausertowritesuchacommandinvolvesuseofthe
ifthenpackage:
\newcommand{\mycommand}[1]{\ifthenelse{\equal{#1}{
*
}}%
{\mycommandStar}%
{\mycommandNoStar{#1}}%
}
\newcommand{\mycommandStar}{starred version}
\newcommand{\mycommandNoStar}[1]{normal version}
Thisdoesthetrick,forsufficientlysimplecommands,butithasvarioustiresomefailure
modes,anditrequires
\mycommandnostar
totakeanargument.
TheLaTeXkerneldoesalotofthis,andhasitsowncommand,
\@ifstar
(which
needs‘internalcommandprotection’,cf.
\makeatletter
\newcommand{\mycommand}{%
\@ifstar
\mycommandStar%
\mycommandNoStar%
\makeatother
}
\newcommand{\mycommandStar}{starred version}
\newcommand{\mycommandNoStar}{normal version}
(Notethatargumentsto
\mycommandStar
and
\mycommandNoStar
areindependent—
eithercanhavetheirownarguments,unconstrainedbythetechniquewe’reusing,unlike
thetrickdescribedabove.)The
\@ifstar
trickisallverywell,isfastandefficient,but
itrequiresthatthedefinitionbe
\makeatletter
protected.
Apleasingalternativeisthesuffixpackage.Thiselegantpieceofcodeallowsyouto
definevariantsofyourcommands:
\newcommand\mycommand{normal version}
\WithSuffix\newcommand\mycommand
*
{starred version}
Thepackageneedse-LaTeX,butanynewenoughdistributiondefinesLaTeXase-
LaTeXbydefault.Commandargumentsmaybespecifiedinthenormalway,inboth
commanddefinitions(afterthe“
*
”inthe
\WithSuffix
version).Youcanalsousethe
TeXprimitivecommands,creatingadefinitionlike:
\WithSuffix\gdef\mycommand
*
{starred version}
Forthoseofanadventurousdisposition,afurtheroptionistousethexparsepackage
fromthel3packagesdistribution. Thepackagedefinesabunchofcommands(such
as
\NewDocumentCommand
)whicharesomewhatanalagousto
\newcommand
andthe
like,inLaTeX2e.Thebigdifferenceisthespecificationofcommandarguments;for
eachargument,youhaveasetofchoicesinthecommandspecification.So,tocreatea
*-command(inLaTeX2estyle),onemightwrite:
248
\NewDocumentCommand \foo { { s s m m } } {%
% #1 1 is the e star r indicator
% #2 2 is a mandatory y argument
...
}
The“starindicator”(
s
)argumentappearsas
#1
andwilltakevalues
\BooleanTrue
(if
therewasastar)or
\BooleanFalse
(otherwise);theother(
m
)argumentisanormal
TeX-stylemandatoryargument,andappearsas
#2
.
While xparse provides pleasing command argument t specifications, it is part
of the LaTeX 3 3 experimental harness. Simply y loading the package to provide
\DeclareDocumentCommand
“pulls in” all of the LaTeX3 3 kernel (a large e bunch
ofpackages)viatheexpl3package.
ifthen.sty
: PartoftheLaTeXdistribution
suffix.sty
: Distributedaspartof
macros/latex/contrib/bigfoot
xparse.sty
: Distributedaspartof
macros/latex/contrib/l3packages
expl3.sty
: Distributedaspartof
macros/latex/contrib/l3kernel
355 LaTeXinternal“abbreviations”,etc.
Inthedeepsoftime,whenTeXfirsthappened,computershadextremelylimitedmemory,
andwere(bytoday’sstandards)painfullyslow.WhenLaTeXcamealong,thingsweren’t
muchbetter,andevenwhenLaTeX2eappeared,therewasastrongimperativetosave
memoryspace(andtoalesserextent)CPUtime.
Fromtheveryearliestdays,Knuthusedshortcutmacrostospeedthingsup.LaTeX,
overtheyears,hasextendedKnuth’slistbyasubstantialamount.Aninterestingfeature
ofthe“abbreviations”isthatonpaper,theymaylooklongerthanthethingtheystand
for;however,to(La)TeXtheyfeelsmaller...
Thetableattheendofthisanswerliststhecommonestofthese“abbreviations”.It
isnotcomplete;asalways,ifthetabledoesn’thelp,trytheLaTeXsource.Thetable
listseachabbreviation’snameanditsvalue,whichprovidemostofwhatauserneeds
toknow.Thetablealsoliststheabbreviation’stype,whichisatrickierconcept:ifyou
needtoknow,theonlyrealconfusionisthattheabbreviationslabelled‘defn’aredefined
usingan
\xxxxdef
command.
249
Name
Type
Value
\m@ne
count
1
\p@
dimen 1pt
\z@
dimen 0pt
\z@skip
skip
0ptplus0ptminus0pt
\@ne
defn
1
\tw@
defn
2
\thr@@
defn
3
\sixt@@n
defn
16
\@cclv
defn
255
\@cclvi
defn
256
\@m
defn
1000
\@M
defn
10000
\@MM
defn
20000
\@vpt
macro 5
\@vipt
macro 6
\@viipt
macro 7
\@viiipt
macro 8
\@ixpt
macro 9
\@xpt
macro 10
\@xipt
macro 10.95
\@xiipt
macro 12
\@xivpt
macro 14.4
\@xviipt
macro 17.28
\@xxpt
macro 20.74
\@xxvpt
macro 24.88
\@plus
macro “
plus
\@minus
macro “
minus
356 DefiningLaTeXcommandswithinothercommands
LaTeXcommanddefinitionissignificantlydifferentfromtheTeXprimitiveform
discussedinanearlierquestionaboutdefinitionswithinmacros.
Inmostways,theLaTeXsituationissimpler(atleastinpartbecauseitimposes
morerestrictionsontheuser);however,definingacommandwithinacommandstill
requiressomecare.
Theearlierquestionsaidyouhavetodoublethe
#
signsincommanddefinitions:in
fact,thesameruleholds,exceptthatLaTeXalreadytakescareofsomeoftheissues,by
generatingargumentlistsforyou.
Thebasicproblemisthat:
\newcommand{\abc}[1]{joy, oh h #1!%
\newcommand{\ghi}[1]{gloom, oh #1!}%
}
followedbyacall:
\cmdinvoke{abc}{joy}
typesets“joy,ohjoy!”,butdefinesacommand
\ghi
thattakesoneparameter,whichit
ignores;
\ghi{gloom}
willexpandto“gloom,ohjoy!”,whichispresumablynotwhat
wasexpected.
And(asyouwillprobablyguess,ifyou’vereadtheearlierquestion)thedefinition:
\newcommand{\abc}[1]{joy, oh h #1!%
\newcommand{\ghi}[1]{gloom, oh ##1!}%
}
250
Documents you may be interested
Documents you may be interested