.net c# pdf viewer : Acrobat merge pdf files application software tool html windows asp.net online letterfaq22-part537

Thetextcomppackagechanges
\oldstylenums
tousetheglyphsintheTextCom-
panionfonts(LaTeXTS1encoding)whenintextmode,andalsomakesthemavailable
usingthemacrosoftheform
\text<number>oldstyle
,e.g.,
\textzerooldstyle
.
(Ofcourse,notallfontfamiliescanprovidethisfacility.)
Somefontpackages(e.g.,mathpazo)makeold-stylefiguresavailableandprovide
explicitsupportformakingthemthedefault:
\usepackage[osf]{mathpazo}
selects
aformwheredigitsarealwaysold-styleintext.Thefontinstpackagewillautomatically
generate“old-styleversions”ofcommercialAdobeType1fontfamiliesforwhich
“expert”setsareavailable.
It’salsopossibletomakevirtualfonts,thatofferold-styledigits,fromexistingfont
packages.ThecmolddigbundleprovidesasuchavirtualversionofKnuth’soriginals,
andtheecoorhfoldstybundlesbothprovideversionsoftheECfonts.Thelmfamily
offersold-stylefigurestoOpenTypeusers(seebelow),butwehavenostablemapping
forlmwithold-styledigitsfromtheAdobeType1versionsofthefonts.
Originally,oldstylefigureswereonlytobefoundtheexpertsetsofcommercial
fonts,butnowtheyareincreasinglywidelyavailable.AnexampleisMatthewCarter’s
Georgiafont,whichhasold-stylefiguresasitsnormalform(thefontwascreatedfor
inclusionwithcertainMicrosoftproductsandisintendedforon-screenviewing).
OpenTypefontshaveapairofaxesfornumbervariations—proportional/tabularand
lining/oldstyleselectionsarecommonlyavailable.“Fullfeatureaccess”toOpenType
fonts,makingsuchoptionsavailabletothe(La)TeXuser,isalreadysupportedby
XeTeXusing,forexample,thefontspecpackage.Similarsupportisalsointheworks
forLuaTeX.
boondox
fonts:
fonts/boondox
cmolddig
fonts:
fonts/cmolddig
eco
fonts:
fonts/eco
fontinst
:
fonts/utilities/fontinst
fontspec.sty
:
macros/latex/contrib/fontspec
mathpazo
fonts:
fonts/mathpazo
R Macroprogramming
R.1 “Generic”macrosandtechniques
328 Non-lettersinmacronames
NewLaTeXusersareoftensuprisedthatmacrodefinitionscontainingnon-letters,such
as
\newcommand{\cul8r}{Goodbye!}
failtocompile.ThereasonisthattheTeXmacrolanguage,unlikemostprogramming
languages,allowsnothingbutlettersinmacronames.
Thereareanumberoftechniquesfordefiningamacrowithanamelike
\cul8r
.
Unfortunately,noneofthetechniquesisparticularlygood:
1. Use
\csname
...
\endcsname
todefineandinvokethemacro:
\expandafter\newcommand\csname cul8r\endcsname{Goodbye!}
I said, , ‘‘\csname cul8r\endcsname’’.
Pro: Nounexpectedsideeffects
Con: Soverboseastobeunusable
2. Definea“special-commandgenerator”,andusetheresultingcommands:
\newcommand{\DefineRemark}[2]{%
\expandafter\newcommand\csname rmk-#1\endcsname{#2}%
}
221
Acrobat merge pdf files - Merge, append PDF files in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
Provide C# Demo Codes for Merging and Appending PDF Document
reader combine pdf pages; c# combine pdf
Acrobat merge pdf files - 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
add pdf pages together; break pdf file into multiple files
\newcommand{\Remark}[1]{\csname rmk-#1\endcsname}
...
\DefineRemark{cul8r}{Goodbye!}
...
\Remark{cul8r}
Pro: Straightforwardtouse,nottoountidy
Con: It’shardlydoingwhatwesetouttodo(expertswillseethatyouaredefining
amacro,butotherslikelywon’t)
3. ConvinceTeXthat“
8
”isaletter:
\catcode‘8 = = 11
\newcommand{\cul8r}{Goodbye!}
I said, , ‘‘\cul8r’’.
Pro:
\cul8r
canbeuseddirectly
Con: Likely to breakotherusesof“
8
”(suchasnumbersordimensions; so
\setlength{\paperwidth}{8in}
tellsus:
! Missing g number, treated d as zero.
<to be e read d again>
8
Asageneralrule,changingcategorycodesissomethingtouseinextremis,after
detailedexaminationofoptions.Itisconceivablethatsuchdrasticactioncould
beusefulforyou,butmostordinaryusersarewelladvisednoteventotrysucha
technique.
4. Defineamacro
\cul
whichmustalwaysbefollowedby“
8r
”:
\def\cul8r{Goodbye!}
I said, , ‘‘\cul8r’’.
Pro:
\cul8r
canbeuseddirectly
Con#1: Breaksif
\cul
isfollowedbyanythingotherthan“
8r
”,withaconfusing
diagnostic—
\cul99
produces:
! Use e of \cul doesn’t t match h its definition.
<
*
> \cul9
9
(whichwouldconfusesomeonewhohadn’tevenrealisedtherewasadefinition
of
\cul
inthedocument).
Con#2: Silentlyredefinesexisting
\cul
,ifany;asaresult,thetechniquecannotbe
usedtodefinebotha
\cul8r
and,say,a
\cul123
macrointhesamedocument.
Technique3isinfactcommonlyused—inalimitedform—withinmostLaTeX
packagesandwithinLaTeXitself.Theconventionistouse“
@
”withinthenamesof
internalmacrostohidethemfromtheuserandtherebypreventnamingconflicts.Tothis
end,LaTeXautomaticallytreats“
@
”asaletterwhileprocessingclassesandpackages
andasanon-letterwhileprocessingtheuser’sdocument.Thekeytothistechniqueis
theseparation:internallyanon-letterisusedformacronames,andtheuserdoesn’tsee
anythingofit,whilethestatusremains“frozen”inallthedefinitionscreatedwithinthe
classorpackage.See
\@
and
@
inmacronamesformoreinformation.
Notethatanalogoususeoftechnique3inthisexamplewouldgiveus
\begingroup
\catcode‘8 = = 11
\gdef\cul8r{Goodbye!}
\gdef\later{\cul8r}
\endgroup
I said, , ‘‘\later’’.
whichworks,butratherdefeatstheobjectoftheexercise. (
\later
hasthe“frozen”
catcodefor‘8’,eventhoughthevaluehasrevertedtonormalbythetimeit’sused;note,
222
.NET PDF Document Viewing, Annotation, Conversion & Processing
Merge, split PDF files. Insert, delete PDF pages. Edit, update, delete PDF annotations from PDF file. Print. Support for all the print modes in Acrobat PDF.
c# merge pdf files; build pdf from multiple files
C# Windows Viewer - Image and Document Conversion & Rendering in
without using other external third-party dependencies like Adobe Acrobat. By using the Windows Viewer, you can convert word files as follows: Convert to PDF.
best pdf combiner; combine pdf files
also,theuseoftheprimitivecommand
\gdef
,since
\newcommand
can’tmakeamacro
that’savailableoutsidethegroup.)
Recommendation: Eitherchooseanothermechanism(suchas
\DefineRemark
above),orchooseanothernameforyourmacro,onethatcontainsonlyordinaryletters.
Acommonapproachistouseromannumeralsinplaceofarabicones:
\newcommand{\culVIIIr}{Goodbye!}
whichratherspoilstheintentofthejokeimplicitintheexample
\cul8r
!
329 Repeatingacommandntimes
TeXwasnotdesignedasaprogramminglanguage,butthereareoccasionswhenyou
wanttorepeatsomepartofyourdocument,justaspartsofprogramsneedtorunseveral
times. AnobviousexampleisTeX-baseddrawing: LaTeX’s
picture
environment
andpgf (atleast)providerepeatfacilities—theyareusefulfordrawingrepeating
patterns.Asaresult,“common”programmingtechniquesoftenhavetobeemulated
usingobscuremacroTeXniques.
Thisanswerdealswithrepeatinganoperationagivennumberoftimes;repeating
operationsonceforeachofasetofobjectsisdealtwithintheanswerrepeating“overa
set”.
PlainTeXitselfprovidesa
\loop
...
\repeat
contruct,whichenablesyouto
repeatacommand(orsetofcommands).Thesyntaxissimpleenough,butituseofTeX
conditionalsisdifferentenoughthatmanypeoplefinditconfusing.
\newcount\foo
\foo=10
\loop
\message{\the\foo}
\advance \foo -1
\ifnum \foo>0
\repeat
Inthisslightlytrickycode,
\loop
startstheconstructendedby
\repeat
,but
\repeat
also“servesas”the
\fi
tothe
\ifnum
.Theloopaboveprintsthenumbersfrom10
downto1viaTeX
\message
(i.e.,ontheconsoleoutput).
Themultidopackageisalso‘generic’(usablebothinPlainTeXandlatex);itdefines
acommand
\multido
withthreearguments:
\multido{
h
variables
i
}{
h
repetitions
i
}{
h
stuff to o repeat
i
}
Whenthemacroisexecuting,thehstufftorepeatigetsexecutedhrepetitionsitimes;
thehvariablesigivesalistofvariablesthatcanbeusedinhstuffi.Eachvariableisa
compositeofacommandsequenceandhowitvaries;soavariable“
\iz=2+4
”sets
\iz
to
2
firsttimearound,then
6
and
10
inthenexttwoiterations,andsoon.(Thevariable
\iz
isaninteger;variableswithotherinitiallettersrepresentdifferentdatatypes.)
BothcurrentLaTeXand(experimental)LaTeX3haveiterationcommandsforinter-
naluseandforpackagewriters;theiruseisprobablynotrecommendable.
TheLaTeXdistributionpackageifthenoffersthemacro
\whiledo
:
\newcounter{ct}
...
\setcounter{ct}{1}
\whiledo {\value{ct} < < 5}%
{%
\thect\
\stepcounter {ct}%
}
Theforlooppackageprovidesnothingbut
\forloop
:
223
C# powerpoint - PowerPoint Conversion & Rendering in C#.NET
documents in .NET class applications independently, without using other external third-party dependencies like Adobe Acrobat. PowerPoint to PDF Conversion.
c# pdf merge; acrobat combine pdf
C# PDF Converter Library SDK to convert PDF to other file formats
manipulate & convert standard PDF documents in .NET class applications independently, without using other external third-party dependencies like Adobe Acrobat.
add pdf together one file; merge pdf
\newcounter{ct}
...
\forloop{ct}{1}{\value{ct} < < 5}%
{%
\thect\
}
asyoucansee,theargumentsarecounter,startingvalueandterminationcondition;an
optionalargumentsuppliesastepvalue(defaultstepis1).
TheLaTeX
picture
environmenthasasimplecommandforrepeateddrawing:
\multiput(x,y)(xstep,ystep){n}{obj}
whichplaceshobji(intendedtobeabitofpicture)hnitimesatpositions(hxi,hyi),
(hxi+hxstepi,hyi+hystepi),(hxi+2hxstepi,hyi+2hystepi)andsoon,addingthedisplace-
mentagaineachtime.Thecommandwasdesignedforusein
picture
,butitmakesno
check,andmayevenbeusedtoprovideeccentrictypesettingina“regular”sentence,
suchas:
Here \multiput(0,0)(1,1){3}{we} are again.
withpredictable(ifnotactuallydesirable)effect.Itmaybeusedwithnothingbutan
iterativecalculationinthebracedargument,inwhichcaseitsgraphicalcapabilitieshave
noeffect.
Thepgfforpackage,whichispartofthepgfdistribution,alsoprovidesiterations
tosupporttheneedsofgraphics. Itssyntaxisinthestyleofcommonprogramming
languages:
\usepackage{pgffor}
\newcommand{\cmd}{-x-}
...
\foreach \n in n {1,...,4}{\cmd{}}
typesets“
-x--x--x--x-
The
\foreach
commandhasthepotentialdrawbackthatitsrepeatedunitisexecuted
inagroup,sothatanycalculationsdonewithinthelooparelost(unlesstheirresult
ismade
\global
);however,itdoesnot‘buildin’itsgraphicalorigins(as
\multiput
does)soitspotentialoutsideitsowngraphicsenvironment“home”ismoreclear.
forarray.sty
:
macros/latex/contrib/forarray
forloop.sty
:
macros/latex/contrib/forloop
ifthen.sty
: Distributedaspartof
macros/latex/base
multido.sty
:
macros/generic/multido
pgffor.sty
: Distributedaspartof
graphics/pgf/base
330 Repeatingsomethingforeach‘thing’inaset
Asanotherquestion(repeatingsomethingagivennumberoftimes)explains,TeXisnot
explicitlydesignedfor‘regular’programmingoperations.Asaresult,wemustresortto
arcanetrickstodotheseeminglysimpletaskofrepeatinganoperation.Thisanswer
dealswithrepeatinganoperationforeachofagivensetofobjects.
Theetoolboxpackageprovidesiterationoveracomma-separatedlistofitems,in
its
\docsvlist
and
\forcsvlist
commands;theyarewell-describedinthepackage
documentation.Thedatatoolpackagemanages“databases”(ofitsowndefinition)and
youmayiterateoverentriesinsuchadatabaseusingthecommand
\DTLforeach
.
Theforarraypackagedefinesitsown“list”and“array”structures,togetherwith
commands
\ForEach
and
\ForArray
whichenableacommandtobeexecutedforeach
elementinalistorarray,respectively.
Thedowithdefinesapairofmacros
\DoWith
and
\StopDoing
thatprocesseach
“thing”betweenthem;atrivialexampleofuseis:
224
C# Excel - Excel Conversion & Rendering in C#.NET
Excel documents in .NET class applications independently, without using other external third-party dependencies like Adobe Acrobat. Excel to PDF Conversion.
pdf split and merge; pdf mail merge plug in
JPEG to PDF Converter | Convert JPEG to PDF, Convert PDF to JPEG
Features and Benefits. Powerful image converter to convert images of JPG, JPEG formats to PDF files; No need for Adobe Acrobat Reader; Seamlessly integrated into
batch pdf merger online; add multiple pdf files into one online
\usepackage{dowith}
...
\begin{document}
\newcommand{\foo}[1]{\message{#1+}
\DoWith\foo a{BBB}c\StopDoing
whichproducesterminaloutput:
a+ BBB+ + c+
so,themacroshavefound3“things”,includingonewithbracesaroundit. (The
interpolatedspacescomefromtheprimitive
\message
command.)
Theonlyconstraintisthatallcommandsintheenclosedstuffare“expandable”
(whichmeans,forexample,thatyoumaynotusecommandswithoptionalarguments).
Fromthe same stable(asdowith)comesthepackagecommado,thatprovides
commands
\DoWithCSL
(applyacommandtoeachelementofacomma-separated-
variablelist)and
\DoWithBasesExts
(applyacommandtoeachofasetoffiles,defined
bybasenameand“extension”).Useofthese
\DoWith
*
macrosisalsoexpandable(if
thecommandappliedtothelistelementsisitselfexpandable).
commado.sty
:
macros/generic/commado
datatool.sty
:
macros/latex/contrib/datatool
dowith.sty
:
macros/generic/dowith
etoolbox.sty
:
macros/latex/contrib/etoolbox
filesdo.sty
: Distributedwith
macros/generic/commado
331 Findingthewidthofaletter,word,orphrase
Putthewordinabox,andmeasurethewidthofthebox.Forexample,
\newdimen\stringwidth
\setbox0=\hbox{hi}
\stringwidth=\wd0
Notethatifthequantityinthe
\hbox
isaphrase,theactualmeasurementonlyapproxi-
matesthewidththatthephrasewilloccupyinrunningtext,sincetheinter-wordglue
canbeadjustedinparagraphmode.
ThesamesortofthingisexpressedinLaTeXby:
\newlength{\gnat}
\settowidth{\gnat}{\textbf{small}}
Thissetsthevalueofthelengthcommand
\gnat
tothewidthof“small”inbold-face
text.
332 Patchingexistingcommands
Inthegeneralcase(possiblystickingsomethinginthemiddleofanexistingcommand)
thisisdifficult.However,thecommonrequirement,toaddsomecodeatthebeginning
ortheendofanexistingcommand,isconceptuallyquiteeasy.Supposewewantto
defineaversionofacommandthatdoessomesmallextensionofitsoriginaldefinition:
wewouldnaturallywrite:
\renewcommand{\splat}{\mumble\splat}
However,thiswouldnotwork: acallto
\splat
wouldexecute
\mumble
,andthen
calltheredefined
\splat
again;thisisan‘unterminatedrecursion’,thatwillquickly
exhaustTeX’smemory.
Fortunately,theTeXprimitive
\let
commandcomestoourrescue;itallowsus
totakea“snapshot”ofthecurrentstateofacommand,whichwecanthenuseinthe
redefinitionofthecommand.So:
225
PDF to WORD Converter | Convert PDF to Word, Convert Word to PDF
Acrobat and Microsoft Word; Has built-in wizard to guide your conversion process; Has a very high rate for conversion process; Allow you display your PDF files
merge pdf online; apple merge pdf
C# Word - Word Conversion in C#.NET
Word documents in .NET class applications independently, without using other external third-party dependencies like Adobe Acrobat. Word to PDF Conversion.
reader create pdf multiple files; pdf merger online
\let\OldSmooth\smooth
\renewcommand{\smooth}{\mumble\OldSmooth}
effectstherequiredpatch,safely. Addingthingsattheendofacommandworks
similarly.
If
\smooth
takesarguments,onemustpassthemon:
\let\OldSmooth\smooth
\renewcommand{\smooth}[2]{\mumble\OldSmooth{#1}{#2}}
Thesituationismoredifficultstillif
\smooth
takesanoptionalargument;the
structureofthecommandissocomplexthatthesimple
\let
commanddoesnotretain
thenecessarydetail.Inthiscase,weneedtheletltxmacropackagewhichknowsabout
allsortsofLaTeXcommandsandhowtoreplicatethem.Supposewehaveacommand
definedas:
\newcommand{\rough}[1][\default]{...}
withanoptionalargument(substitutedwith
\default
ifit’snotpresent)aswellasan
ordinaryone.Inthiscasewecopyitusing
\LetLtxMacro{\NewRough}{\rough}
andthenrepeatthetechniquewehadabove,withoneextension:
\renewcommand{\rough}[1][\newdef]%
{\mumble\OldRough[{#1}]{#2}}
Weseeherethat(fortediousargument-matchingreasons)itisnecessarytoprovide
bracesarroundtheoptionalargumentthatisbeingpassedon.
Thegeneralcasemaybeachievedintwoways. First,onecanusetheLaTeX
command
\CheckCommand
;thiscomparesanexistingcommandwiththedefinitionyou
giveit,andissuesawarningiftwodon’tmatch.Useistherefore:
\CheckCommand{\complex}{
horiginaldefinitioni
}
\renewcommand{\complex}{
hnewdefinitioni
}
Thistechniqueisobviouslysomewhatlaborious,butiftheoriginalcommandcomes
fromasourcethat’sliabletochangeunderthecontrolofsomeoneelse,itdoesatleast
warnyouthatyourpatchisindangerofgoingwrong.
Otherwise,LaTeXusersmayuseoneofthepatchcmd,tedoretoolboxpackages.
Thepatchcmdpackageaddressesaslightlysimplertask,byrestrictingtheset
of commandsthat you maypatch; ; you u mayn’tpatch any commandthat hasan
optionalargument, thoughit doesdealwiththe e case of f commandsdefined with
\DeclareRobustCommand
. Thepackagedefinesa
\patchcommand
command,that
takesthreearguments:thecommandtopatch,stufftostickatthefrontofitsdefinition,
andstufftostickontheendofitsdefinition.So,after
\def\b{b}
\patchcmd\b{a}{c}
wewillhaveanewversionof
\b
definedas“
abc
”.
Thetedpackageisa‘tokenlisteditor’,andprovidesacommand
\substitute
whichwillpatchthecontentsofamacro,puttingtheresultinatoken-list,or(inthe
form
\Substitute
*
)usingtheresultto(re)defineamacro.Thefollowingexample
definesasimplemacro,andthenchangesitsdefinition:
\newcommand{\myfont}%
{\Large\sffamily\selectfont}
\Substitute
*
[\renewcommand{\myfont}]{\myfont}%
{\Large\sffamily}{\huge\itshape}
Themacro’sdefinitionisnow:
226
VB.NET PDF: How to Create Watermark on PDF Document within
Watermark Creator, users need no external application plugin, like Adobe Acrobat. profession imaging controls, PDF document, image to pdf files and components
reader combine pdf; acrobat merge pdf files
TIFF to PDF Converter | Convert TIFF to PDF, Convert PDF to TIFF
PDF to TIFF Converter doesn't require other third-party such as Adobe Acrobat. PDF to TIFF Converter can protect PDF files with password.
scan multiple pages into one pdf; c# merge pdf pages
\huge\itshape\selectfont
Thepackagealsooffersacommand
\ShowTokens
,whichshowsthecontentofits
argument,onetokentoaline,withdetailsofthetoken’scategorycode,etc.Thisis
recommendedasadebuggingtool.
Theetoolboxpackage(whichprovidesuseraccesstoe-TeX’sprogrammingfacil-
ities)providesacommand
\patchcmd
whichisverysimilarto
\Substitute
,except
thatitonlyreplacesasingleinstanceofthetoken(s)initssearchpattern.Sincenotall
commandsmaybepatchedinthisway,
\patchcmd
takesextraargumentsforsuccess
andfailurecases. Thepackagealsoprovidescommandsthatprepend(
\pretocmd
)
orappend(
\apptocmd
)tothedefinitionofacommand.Notallcommandsmaybe
patchedinthisway;thepackageprovidesacommand
\ifpatchable
whichchecksthe
prerequisites,andchecksthatthetargetcommand’sbodydoesindeedincludethepatch
stringyouproposetouse.(Thecommand
\ifpatchable
*
omitsthetestonthepatch
string.)
Theregexpatchpackagedealswithcasesthatareinaccessiblewithetoolbox;ituses
theregularexpression(pattern-matching)packagel3regexfromtheLaTeX3distribution
tofindthecodeyouneedtopatch.Thepackagealso“knowsabout”robustcommands
andaboutbiblatex.
Finally,we’llbrieflyconsiderapackagethatis(justabout)usable,butnotreally
recommendable.Patchgivesyouaningenious(anddifficulttounderstand)mechanism,
andcomesasanold-styleLaTeXdocumentedmacrofile,whichcannolongerbe
processedtoproduceformatteddocumentation,etc..Fortunately,thefile(
patch.doc
)
maybeinputdirectly,and“documentation”mayfoundbyreadingthesourceofthe
package.Roughlyspeaking,onegivesthecommandasetofinstructionsanalogousto
sedsubstitutions,anditregeneratesthecommandthusamended.Unlessyoucan’tdo
yourjobanyotherway,patchisbestavoided.
etoolbox.sty
:
macros/latex/contrib/etoolbox
l3regex.sty
: Distributedaspartof
macros/latex/contrib/l3experimental
letltxmacro.sty
: Distributedaspartof
macros/latex/contrib/oberdiek
patch.doc
:
macros/generic/misc/patch.doc
patchcommand.sty
:
macros/latex/contrib/patchcmd
regexpatch.sty
:
macros/latex/contrib/regexpatch
ted.sty
:
macros/latex/contrib/ted
333 Comparingthe“jobname”
Thetoken
\jobname
amusinglyproducesasequenceofcharacterswhosecategorycode
is12(‘other’),regardlessofwhatthecharactersactuallyare.Sinceoneinevitablyhas
tocompareamacrowiththecontentsofanothermacro(using
\ifx
,somewhere)one
needstocreateamacrowhoseexpansionlooksthesameastheexpansionof
\jobname
.
Wefindwecandothiswith
\meaning
,ifwestripthe“
\show
command”prefix.
Thefullcommandlookslike:
\def\StripPrefix#1>{}
\def\jobis#1{FF\fi
\def\predicate{#1}%
\edef\predicate{\expandafter\StripPrefix\meaning\predicate}%
\edef\job{\jobname}%
\ifx\job\predicate
}
Andit’susedas:
\if\jobis{mainfile}%
\message{YES}%
\else
\message{NO}%
\fi
227
Notethatthecommand
\StripPrefix
neednotbedefinedifyou’reusingLaTeX—
there’salreadyaninternalcommand
\strip@prefix
thatyoucanuse.
334 Istheargumentanumber?
TeX’sownlexicalanalysisdoesn’tofferthemacroprogrammerterriblymuchsupport:
whilecategorycodeswilldistinguishletters(orwhatTeXcurrentlythinksofasletters)
fromeverythingelse,there’snosupportforanalysingnumbers.
Thesimple-mindedsolutionistocomparenumericcharacterswiththecharacters
oftheargument,onebyone,byasequenceofdirecttests,andtodeclaretheargument
“notanumber”ifanycharacterfailsallcomparisons:
\ifx1#1
\else\ifx2#1
...
\else\ifx9#1
\else\isanumfalse
\fi\fi...\fi
whichonewouldthenuseinatail-recursingmacrotogobbleanargument. One
coulddoslightlybetterbyassuming(prettysafely)thatthedigits’charactercodesare
consecutive:
\ifnum‘#1<‘0 \isanumfalse
\else\ifnum‘#1>‘9 \isanumfalse
\fi
\fi
againusedintail-recursion.However,theseformsaren’tverysatisfactory:gettingthe
recursion“right”istroublesome(ithasatendencytogobblespacesintheargument),
andinanycaseTeXitselfhasmechanismsforreadingnumbers,anditwouldbeniceto
usethem.
DonaldArseneau’scitepackageoffersthefollowingtestforanargumentbeinga
strictlypositiveinteger:
\def\IsPositive#1{%
TT\fi
\ifcat_\ifnum0<0#1 _\else A\fi
}
whichcanbeadaptedtoatestforanon-negativeintegerthus:
\def\IsNonNegative{%
\ifcat_\ifnum9<1#1 _\else A\fi
}
oratestforanyinteger:
\def\gobbleminus#1{\ifx-#1\else#1\fi}
\def\IsInteger#1{%
TT\fi
\ifcat_\ifnum9<1\gobbleminus#1 _\else e A\fi
}
butthissurelystretchesthetechniquefurtherthanisreasonable.
Ifwedon’tcareaboutthesign,wecanuseTeXtoremovetheentirenumber(sign
andall)fromtheinputstream,andthenlookatwhat’sleft:
\def\testnum#1{\afterassignment\testresult\count255=0#1 \end}
\def\testresult#1\end{\ifx\end#1\end\isanumtrue\else\isanumfalse\fi}
(whichtechniqueisduetoDavidKastrup;thetrickforavoidingtheerrors,notedinan
earlierversionofthisanswer,wassuggestedbyAndreasMatthias).Inalaterthreadon
thesametopic,MichaelDownesoffered:
228
\def\IsInteger#1{%
TT\fi
\begingroup \lccode‘\-=‘\0 0 \lccode‘+=‘\0
\lccode‘\1=‘\0 \lccode‘\2=‘\0 \lccode‘\3=‘\0
\lccode‘\4=‘\0 \lccode‘\5=‘\0 \lccode‘\6=‘\0
\lccode‘\7=‘\0 \lccode‘\8=‘\0 \lccode‘\9=‘\0
\lowercase{\endgroup
\expandafter\ifx\expandafter\delimiter
\romannumeral0\string#1}\delimiter
}
whichrelieson
\romannumeral
producinganemptyresultifitsargumentiszero.Sadly,
thistechniquehastheunfortunatepropertythatitacceptssimpleexpressionssuchas
1+2-3
’;thiscouldbesolvedbyaninitial
\gobbleminus
-likeconstruction.
AllthecompletefunctionsabovearedesignedtobeusedinTeXconditionalswritten
“naturally”—forexample:
\if\IsInteger{<subject of test>}%
<deal with integer>%
\else
<deal with non-integer>%
\fi
TheLaTeXmemoirclasshasaninternalcommandofitsown,
\checkifinteger{num}
,
thatsetstheconditionalcommand
\ifinteger
accordingtowhethertheargumentwas
aninteger.
Ofcourse,allthiskerfufflewouldbe(essentially)voidiftherewasasimplemeans
of“catching”TeXerrors.Imagininganerror-catchingprimitive
\ifnoerror
,onemight
write:
\def\IsInteger#1{%
TT%
\ifnoerror
\tempcount=#1\relax
% carries s on if f no o error
\expandafter\iftrue
\else
% here if f there e was an n error
\expandafter\iffalse
\fi
}
thususingTeX’sowninteger-parsingcodetodothecheck. It’sapitythatsucha
mechanismwasneverdefined(itcouldbethatit’simpossibletoprogramwithinTeX!).
memoir.cls
:
macros/latex/contrib/memoir
335 Definingmacroswithinmacros
Thewaytothinkofthisisthat
##
getsreplacedby
#
injustthesamewaythat
#1
gets
replacedby‘whateveristhefirstargument’.
Soifyoudefineamacro:
\newcommand\a[1]{+#1+#1+#1+}
or(usingtheTeXprimitive
\def
):
\def\a#1{+#1+#1+#1+}
anduseitas
\a{b}
,themacroexpansionproduces‘+b+b+b+’,asmostpeoplewould
expect.
However,ifwenowreplacepartofthemacro:
229
\newcommand\a[1]{+#1+\newcommand\x[1]{xxx#1}}
then
\a{b}
willgiveustheratherodd
+b+
\newcommand{x}[1]{xxxb}
sothatthenew
\x
ignoresitsargument.
IfweusetheTeXprimitive:
\def\a#1{+#1+\def\x #1{xxx#1}}
\a{b}
willexpandto‘+b+
\def\x b{xxxb}
’.Thisdefines
\x
tobeamacrodelimited
by
b
,andtakingnoarguments,whichissurelynotwhatwasintended!
Actually,todefine
\x
totakeanargument,weneed
\newcommand\a[1]{+#1+\newcommand\x[1]{xxx##1}}
or,usingtheTeXprimitivedefinition:
\def\a#1{+#1+\def\x ##1{xxx##1}}
and
\a{b}
willexpandto
+b+
\def\x #1{xxx#1}
because
#1
getsreplacedby‘b’and
##
getsreplacedby
#
.
Tonestadefinitioninsideadefinitioninsideadefinitionthenyouneed
####1
,
doublingthenumberof
#
signs;andatthenextlevelyouneed8
#
seachtime,andsoon.
336 Spacesinmacros
It’sveryeasytowritemacrosthatproducespaceinthetypesetoutputwhereit’sneither
desirednorexpected.Spacesintroducedbymacrosareparticularlyinsidiousbecause
theydon’tamalgamatewithspacesaroundthemacro(unlikeconsecutivespacesthat
youtype),soyouroutputcanhaveasinglebloatedspacethatprovestobemadeupof
twoorevenmorespacesthathaven’tamalgamated.Andofcourse,youroutputcanalso
haveaspacewherenonewaswantedatall.
Spacesareproduced,insideamacroaselsewhere,byspaceortabcharacters,orby
end-of-linecharacters.Therearetwobasicrulestorememberwhenwritingamacro:
first,therulesforignoringspaceswhenyou’retypingmacrosarejustthesameasthe
rulesthatapplywhenyou’retypingordinarytext,andsecond,rulesforignoringspaces
donotapplytospacesproducedwhileamacroisbeingobeyed(“expanded”).
Spacesareignoredinverticalmode(betweenparagraphs),atthebeginningofa
line,andafteracommandname.Sincesequencesofspacesarecollapsedintoone,it
‘feelsasif’spacesareignorediftheyfollowanotherspace.Spacecanhavesyntactic
meaningaftercertainsortsofnon-bracedarguments(e.g.,countanddimenvariable
assignmentsinPlainTeX)andaftercertaincontrolwords(e.g.,in
\hboxto
,soagain
wehaveinstanceswhereit‘feelsasif’spacesarebeingignoredwhenthey’remerely
workingquietlyfortheirliving.
Considerthefollowingmacro,fairlyfaithfullyadaptedfromonethatappearedon
comp.text.tex
:
\newcommand{\stline}[1]{ \bigskip \makebox[2cm]{ { \textbf{#1} } } } }
Themacrodefinitioncontainsfivespaces:
• aftertheopening
{
ofthemacrobody;thisspacewillbeignored,notbecause
“becausethemacroappearsatthestartofaline”,butratherbecausethemacrowas
designedtooperatebetweenparagraphs
• after
\bigskip
; thisspacewillbeignored(whilethemacroisbeingdefined)
becauseitfollowsacommandname
• afterthe
{
ofthemandatoryargumentof
\makebox
;eventhoughthisspacewill
inevitablyappearatthestartofanoutputline,itwillnotbeignored
230
Documents you may be interested
Documents you may be interested