asp.net mvc 4 and the web api pdf free download : Merge pdf files Library application component .net azure asp.net mvc memman32-part1380

15.3. Verbatims
\newcommand{\nobvbox}{%
\bvperpagefalse
\renewcommand{\bvtoprulehook}{}%
\renewcommand{\bvleftsidehook}{}%
\renewcommand{\bvrightsidehook}{}%
\renewcommand{\bvendrulehook}{}%
\renewcommand{\bvtopmidhook}{\rule{0pt}{2\fboxsep} \hss}%
}
Thedefinitionsoftheotherstyles,
\bvtopandtail
and
\bvsides
,areintermediatebe-
tween
\bvbox
and
\nobvbox
intheobviousmanner.
\linenumberfrequency{
nth
}
\resetbvlinenumber
\setbvlinenums{
first
}{
startat
}
\linenumberfont{
fontdeclaration
}
The command
\linenumberfrequency
controls the numbering g of lines s in a
boxedverbatim
—everynthlinewillbenumbered.Ifnthis0orless,thennolinesare
numbered,ifnthis1theneachlineisnumbered,andifnthis
n
,where
n
is2ormore,
thenonlyevery
n
thlineisnumbered.Linenumberingiscontinuousfromoneinstanceof
the
boxedverbatim
environmenttothenext. Outsidetheenvironmentthelinenumbers
canberesetatanytimebythecommand
\resetbvlinenumber
.
The
\setbvlinenums
macrocanbeusedtospecifythatthenumberofthefirstlineof
thefollowing
boxedverbatim
shallbefirstandthefirstprintednumbershallbestartat.
The
\linenumberfont
declarationsetsfontdeclarationasthefontforthelinenum-
bers.Thedefaultspecificationforthisis:
\linenumberfont{\footnotesize\rmfamily}
Linenumbersarealwayssetattheleftofthelinesbecausethereisnotellinghowlonga
linemightbeanditmightclashwithalinenumbersetattheright.
\bvnumbersinside
\bvnumbersoutside
Linenumbersaretypesetinsidetheboxafterthedeclaration
\bvnumberinside
andare
typesetoutsidetheboxafterthedeclaration
\bvnumbersoutside
.Thedefaultistoprint
thenumbersinsidethebox.
Verbatimtabbing,butnotwrapping,appliestothe
boxedverbatim
environment.
15.3.2 Newverbatims
Theclassimplementationofverbatimsletsyoudefineyourownkindofverbatimenvi-
ronment.Unfortunatelythisisnotquiteassimpleassaying
\newverbatim{myverbatim}{...}{...}
asyoucanfordefiningnormalenvironments.Instead,thegeneralschemeis
\newenvironment{myverbatim}%
{<non-verbatim stuff> \verbatim m <more non-verbatim stuff>}%
{\endverbatim}
Inparticular,youcannotuseeitherthe
\begin
or
\end
macrosinsidethedefinitionofthe
newverbatimenvironment.Forexample,thefollowingcodewillnotwork
283
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
c# merge pdf pages; pdf combine two pages into one
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
batch merge pdf; .net merge pdf files
15. B
OXES
,
VERBATIMSANDFILES
\newenvironment{badverbatim}%
{NBG\begin{verbatim}}{\end{verbatim}}
andthiswon’tworkeither
\newenvironment{badverbatim}%
{\begin{env}\verbatim}{\endverbatim\end{env}}
And, aswiththestandard
verbatim
environment,youcannot usethenewoneinthe
definitionofanewcommand.
Foranexampleofsomethingthatdoeswork,thisnextlittlepieceoftypesettingwas
doneinanewverbatimenvironmentIhavecalled
verbexami
,whichstartsandendswith
ahorizontalrule,anditshowsthedefinitionof
verbexami
.
Theverbexamienvironment
\newenvironment{verbexami}%
{\par\noindent\hrule The verbexami environment t \verbatim}%
{\endverbatim\hrule}
Andthisisavariationonthetheme,withtheenvironmentagainbeingenclosedby
horizontalrules.
Verbexamii
Is this fun?
\newenvironment{verbexamii}%
{\vspace{0.5\baselineskip}\hrule \vspace{0.2\baselineskip}
Verbexamii \verbatim \textsc{Is this fun?}}%
{\endverbatim\hrule\vspace{0.3\baselineskip}}
Asnodoubtyouagree,thesearenotmemorableexamplesofthetypesetter’sartbut
doindicatethatyoucandefineyourownverbatimenvironmentsandmayneedtotakea
bitofcaretogetsomethingthatpassesmuster.
Iwillgivesomemoreusefulexamples,butmainlybasedonenvironmentsforwriting
verbatimfilesasIthinkthattheseprovideabroaderscope.
15.3.3 Example:the
lcode
environment
InthismanualalltheexampleLaTeXcodehasbeentypesetinthe
lcode
environment;this
isaverbatimenvironmentdefinedespeciallyforthepurpose. BelowIdescribethecode
fordefiningmy
lcode
environment, but firsthere isasimpledefinitionofaverbatim
environment,whichIwillcall
smallverbatim
,thatusesthe
\small
fontinsteadofthe
normalsizefont.
\newenvironment{smallverbatim}%
{\setverbatimfont{\normalfont\ttfamily\small}%
\verbatim}%
{\endverbatim}
The
verbatim
environmentisimplementedasakindof
trivlist
,andlistsusually
haveextraverticalspacebeforeandafterthem. FormyenvironmentIdidnotwantany
extraspacingsoIdefinedthemacro
\@zeroseps
tozerotherelevantlistspacings. Ialso
284
Online Merge PDF files. Best free online merge PDF tool.
Online Merge PDF, Multiple PDF files into one. Download Free Trial. Easy converting! We try to make it as easy as possible to merge your PDF files.
how to combine pdf files; apple merge pdf
C# PDF File Split Library: Split, seperate PDF into multiple files
Also able to combine generated split PDF document files with other PDF files to form a new PDF file. Split PDF Document into Multiple PDF Files in C#.
pdf merge documents; c# combine pdf
15.4. Files
wantedthecodelinestobeinsetalittle,soIdefinedanewlengthcalled
\gparindent
to
useastheindentation.
\makeatletter
\newcommand{\@zeroseps}{\setlength{\topsep}{\z@}%
\setlength{\partopsep}{\z@}%
\setlength{\parskip}{\z@}}
\newlength{\gparindent} \setlength{\gparindent}{\parindent}
\setlength{\gparindent}{0.5\parindent}
% Now, the environment t itself
\newenvironment{lcode}{\@zeroseps
\renewcommand{\verbatim@startline}{%
\verbatim@line{\hskip\gparindent}}
\small\setlength{\baselineskip}{\onelineskip}\verbatim}%
{\endverbatim
\vspace{-\baselineskip}%
\noindent
}
\makeatother
Unlessyouareintimatelyfamiliarwiththeinnerworkingsofthe
verbatim
processing
youdeserveanexplanationofthe
lcode
definition.
Extremelyroughly,thecodefor
\verbatim
lookslikethis:
\def\verbatim{%
\verbatim@font
% for r each line, until \end{verbatim}
\verbatim@startline
% collect the characters s in n \verbatim@line
\verbatim@processline{\the\verbatim@line\par}
% repeat for the next line
}
Thecodefirstcalls
\verbatim@font
tosetthefonttobeused.Then,foreachlineitdoes
thefollowing:
 Callsthemacro
\verbatim@startline
tostartofftheoutputversionoftheline.
 Collects s all the characters comprising the line as a single token called
\verbatim@line
.
 Ifthecharactersarethestring‘
\end{verbatim}
’itfinishestheverbatimenviron-
ment.
 Otherwiseitcallsthemacro
\verbatim@processline
whoseargumentisthechar-
actersintheline,treatedasaparagraph. Itthenstartsalloveragainwiththenext
line.
Iconfiguredthe
\verbatim@startline
macrotoindentthelineoftextusingahori-
zontalskipof
\gparindent
.Therestoftheinitialisationcode,beforecalling
\verbatim
todotherealprocessing,justsetsuptheverticalspacing.
15.4 F
ILES
LaTeXreadsandwritesvariousfilesasitprocessesadocument. Obviouslyitreadsthe
documentsourcefile,orfiles,anditwritesthe
log
filerecordingwhatithasdone.Italso
readsandwritesthe
aux
file,andmayreadandwriteotherfileslikea
toc
file.
285
C# TIFF: C#.NET Code to Merge and Append TIFF Files
string[] tifFiles = new string[] { @"C:\demo1.tif", @"C:\demo2.tif" }; // Merge these Tiff files to a single Tiff file and save it to output.tif.
append pdf files reader; split pdf into multiple files
VB.NET PDF Convert to HTML SDK: Convert PDF to html files in vb.
' Convert PDF file to HTML5 files DocumentConverter.ConvertToHtml5("..\1.pdf", "..output\", RelativeType.SVG). Copyright © <2000-2016> by <RasterEdge.com>.
acrobat split pdf into multiple files; batch pdf merger
15. B
OXES
,
VERBATIMSANDFILES
OnoccasionsitcanbeusefultogetLaTeXtoreadand/orwriteotherfilesofyourown
choosing.UnfortunatelystandardLaTeXdoesnotprovideanyeasymethodfordoingthis.
Thememoirclasstriestorectifythis.
\jobname
WhenyourunLaTeXonyoursourcefile,say
fred.tex
,LaTeXstoresthenameofthisfile
(
fred
)inthemacro
\jobname
.LaTeXusesthistonamethevariousfilesthatitwritesout
—the
dvi
or
pdf
file,the
log
file,the
aux
file,etc.
TeXcanreadfrom16inputstreamsandcanwriteto16outputstreams. Normallyan
inputstreamisallocatedforeachkindoffilethatwillbereadandanoutputstreamfor
eachkindoffilethatwillbewritten. Onthe e inputside, then, at leasttwostreamsare
allocated,oneforthesource
tex
fileandoneforthe
aux
file.Ontheoutputsideagainat
leasttwostreamsareallocated,oneforthe
log
fileandoneforthe
aux
file.When
toc
and
othersimilarfilesarealsopartoftheLaTeXprocessyoucanseethatmanyofthe16input
andoutputstreamsmaybeallocatedbeforeyoucangettouseoneyourself.
\newoutputstream{
stream
}
\newinputstream{
stream
}
Themacros
\newoutputstream
and
\newinputstream
respectivelycreateanewoutput
andinputstreamcalledstream,wherestreamshouldbeastringofalphabeticcharacters,
like
myout
or
myin
. Thestreamnamesmustbeunique,youcannotusethesamename
fortwostreamsevenifoneisainputstreamandtheotherisanoutputstream. Ifallthe
16streamsofthegiventypehavealreadybeenallocatedTeXwillissueamessagetelling
youaboutthis,oftheform:
No room for a new write
% for an n output stream
No room for a new read
% for an n input t stream
The two
\new...stream
commands also o provide two empty macros called
\atstreamopen<stream>
and
\atstreamclose<stream>
.Ifthesemacrosalreadyexist
thentheyareleftundisturbed.Forexampleifyoudo:
\newcommand{\atstreamopenmyout}{...}
\newoutputstream{myout}
\newinputstream{myin}
Thenyouwillfindthatthreenewcommandshavebeencreatedlike:
\newcommand{\atstreamclosemyout}{}
\newcommand{\atstreamopenmyin}{}
\newcommand{\atstreamclosemyin}{}
Youcanuse
\renewcommand
tochangethedefinitionsoftheseifyouwish.
\IfStreamOpen{
stream
}{
true-code
}{
false-code
}
Themacro
\IfStreamOpen
checkswhetherornotthestreamstreamisopen.Ifitisthen
thetrue-codeargumentisprocessed,whilewhenitisnotopenthefalse-codeargument
isprocessed.
286
C# Word - Merge Word Documents in C#.NET
File: Merge Word Files. |. Home ›› XDoc.Word ›› C# Word: Merge Word Files. Combine and Merge Multiple Word Files into One Using C#.
c# merge pdf; acrobat merge pdf
C# PDF Convert to HTML SDK: Convert PDF to html files in C#.net
How to Use C#.NET Demo Code to Convert PDF Document to HTML5 Files in C#.NET Class. Add necessary references: RasterEdge.Imaging.Basic.dll.
pdf merge comments; all jpg to one pdf converter
15.4. Files
15.4.1 Writingtoafile
Onestreammaybeusedforwritingtoseveraldifferentfiles,althoughnotsimultaneously.
\openoutputfile{
filename
}{
stream
}
\closeoutputstream{
stream
}
Thecommand
\openoutputfile
opensthe file called filename,eithercreatingitifit
doesnotexist, oremptyingit ifitalreadyexists. . Itthenattachesthefiletotheoutput
streamcalledstreamsothatitcanbewrittento,andthenfinallycallsthemacronamed
\atstreamopen<stream>
.
The
command
\closeoutputstream
firstly
calls
the
macro
named
\atstreamclose<stream>
thenclosestheoutputstreamstream,andfinallydetaches
andclosestheassociatedfile.
\addtostream{
stream
}{
text
}
The
\addtostream
commandwritestexttotheoutputstreamstream,andhenceto
whateverfileiscurrentlyattachedtothestream. Thestreammustbeopen. Anycom-
mandswithinthetextargumentwillbeprocessedbeforebeingwritten.Topreventcom-
mandexpansion,precedethecommandinquestionwith
\protect
.
Writingverbatimtexttoafileistreatedspeciallyasitislikelytobethemostcommon
usage.
\begin{verbatimoutput}{
file
}
anything
\end{verbatimoutput}
\begin{writeverbatim}{
stream
}
anything
\end{writeverbatim}
Thetextwithina
verbatimoutput
environmentiswrittenverbatimtothefilefile. Al-
ternatively,thecontentsofthe
writeverbatim
environmentarewrittenverbatimtothe
streamstream.
Specifically,
verbatimoutput
opensthespecifiedfile,writestoit,andthenclosesthe
file. Thismeansthatif
verbatimoutput
isusedmorethanoncetowritetoagivenfile,
thenonlythecontentsofthelastoftheseoutputsiscapturedinthefile.Ontheotherhand,
youcanuse
writeverbatim
severaltimestowritetothefileattachedtothestreamand,
providingthestreamhasnotbeenclosedinthemeantime,allwillbecaptured.
15.4.2 Readingfromafile
Onestreammaybeusedforreadingfromseveralfiles,althoughnotsimultaneously.
\openinputfile{
filename
}{
stream
}
\closeinputstream{
stream
}
Thecommand
\openinputfile
opensthefilecalledfilenameandattachesittothein-
putstreamcalledstreamsothatitcanbereadfrom. Finallyitcallsthemacronamed
\atstreamopen<stream>
.Itisanerroriffilenamecannotbefound.
Thecommand
\closeinputstream
callsthemacronamed
\atstreamclose<stream>
,
closestheoutputstreamstream,andthendetachesandclosestheassociatedfile.
\readstream{
stream
}
287
C# PowerPoint - Merge PowerPoint Documents in C#.NET
File: Merge PowerPoint Files. |. Home ›› XDoc.PowerPoint ›› C# PowerPoint: Merge PowerPoint Files. C# DLLs: Merge PowerPoint Files.
combine pdf online; add two pdf files together
VB.NET PDF File Split Library: Split, seperate PDF into multiple
splitter control provides VB.NET developers an easy to use solution that they can split target multi-page PDF document file to one-page PDF files or they can
c# merge pdf files into one; pdf combine files online
15. B
OXES
,
VERBATIMSANDFILES
Thecommand
\readstream
readstheentirecontentsofthefilecurrentlyassociatedwith
theinputstreamstream.Thisprovidesthesamefunctionalityas
\input{
filename
}
.
\readaline{
stream
}
The
\readaline
readswhatTeXconsiderstobeonelinefromthefilethatiscurrently
associatedwiththeinputstreamstream.
Multiplelinescanbereadbycalling
\readaline
multipletimes.Awarningisissued
iftherearenomorelinestoberead(i.e.,theendofthefilehasbeenreached).
Justasforwriting,readingfilesverbatimistreatedspecially.
\verbatiminput{
file
}\verbatiminput*{
file
}
\boxedverbatiminput{
file
}\boxedverbatiminput*{
file
}
\readverbatim{
stream
}\readverbatim*{
stream
}
\readboxedverbatim{
stream
}\readboxedverbatim*{
stream
}
The commands
\verbatiminput
and
\boxedverbatiminput
, and d their r starred d ver-
sions,actlikethe
verbatim
and
boxedverbatim
environments,exceptthattheygettheir
textfromthefilefile. Itisanerroriffilecannotbefound. Similarly,
\readverbatim
and
\readboxedverbatim
gettheirtextfromthefilecurrentlyattachedtothestream
inputstream.Itisanerrorifstreamisnotopenforinput.
15.4.3 Example:endnotes
Inanearierversionofthemanual,thissectioncontainedanexampleastohowonecouldmake
endnotes. Theexampleisnowirrelevant,sincememoircontainsomethingsimilartoendnotes
calledpagenotes,seesection12.6onpage245.
Thoseinterestedinthecodefromtheoldexample,canfinditinthemanualsource(ithasjust
beencommentedout).
15.4.4 Example:endfloats
Therearesomedocumentswhereallfiguresarerequiredtobegroupedinoneplace,for
instanceattheendofthedocumentorperhapsattheendofeachchapter.Groupingatthe
endofadocumentwithchaptersisharder,sowe’lltacklethatone.
Thebasicideaistowriteoutverbatimeachfigureenvironmentandthenreadthemall
backinattheend. Wewilluseastream,let’scallit
tryout
,andcallourfileforfigures
tryout.fig
.
\newoutputstream{tryout}
\openoutputfile{tryout.fig}{tryout}
Ifallweresimple,inthedocumentwecouldthenjustdo
\begin{writeverbatim}{tryout}
\begin{figure} ... \end{figure}
\end{writeverbatim}
...
\closeoutputstream{tryout}
\input{tryout.fig}
So,what’stheproblem?
Bydefaultfigurecaptionsarenumberedperchapter,andarepreceededbythechapter
number;moreprecisely,thedefinitionofafigurenumberis
288
15.4. Files
\thechapter.\arabic{figure}
Ifwesimplylumpallthefiguresattheend,thentheywillallbenumberedasiftheywere
inthefinalchapter. Forthesakeofargumentassumethatthelastchapterisnumber10.
Thenthfigurewillthenbenumbered10.n. Onethingthatwecandorathersimplyisto
changethedefinitionofthefigurebyusinganothercounter,let’scallit
pseudo
,insteadof
thechapter.
\newcounter{pseudo}
\renewcommand{\thepseudo}{\arabic{pseudo}}
\renewcommand{\thefigure}{\thepseudo.\arabic{figure}}
Now, allweshouldhavetodoisarrangethatthe propervalue of
pseudo
isavailable
beforeeachfigureistypesetattheend.Thecodearoundthe
figure
environmentsmight
thenlooklikethis
\addtostream{tryout}{\protect\setcounter{pseudo}{\thechapter}}
\begin{writeverbatim}{tryout}
\begin{figure}...
andapartofthefilemightthenlooklike
...
\setcounter{pseudo}{4}
\begin{figure}...
The
\protect
beforethe
\setcounter
commandwillstopitfromexpandingbeforeitis
writtentothefile,whilethe
\thechapter
commandwillbeexpandedtogivetheactual
numberofthecurrentchapter.Thislooksbetterasnowatleastthefigurewillbenumbered
4.ninsteadof10.n.
Thereisonelastsnag—figurenumbersareresetatthestartofeachchapter—but
ifwejustdumpthefiguresattheendofthedocumentthenalthoughthechapterpartof
thenumberwillalterappropriatelybecauseofthe
pseudo
process,thesecondpartofthe
numberwilljustincreasecontinuously. Itlooksasthoughweshouldwriteoutachange
tothechaptercounteratthestartofeachchapter. Ifwedothat,thenweshouldbeable
togetridofthe
pseudo
counter,whichsoundsgood. But,andthisisalmostthelastbut,
whatiftherearechaptersafterwehavereadinthefigurefile?Tocaterforthisthechapter
numberofthelastchapterbeforethefilemustbesaved,andthenrestoredafterthefigures
havebeenprocessed.
Finally,wouldn’titbemuchbetterfortheuserifeverythingwaswrappedupinan
environmentthathandledallthemessystuff?
HereisthefinalcodethatIamgoingtoproducewhich,bytheway,isdisplayedinthe
boxedverbatim
environmentwithlinenumbersandthefollowingsettings,justincase
thereisapagebreakinthemiddleofthebox.
\nobvbox
\bvperpagetrue
\bvtopofpage{\begin{center}\normalfont%
(Continued from m previous s page)\end{center}}
\bvendofpage{}
\resetbvlinenumber
\linenumberfrequency{1}
\bvnumbersoutside
\linenumberfont{\footnotesize\rmfamily}
289
15. B
OXES
,
VERBATIMSANDFILES
\begin{boxedverbatim}
...
1
\newoutputstream{tryout}
2
\openoutputfile{\jobname.fig}{tryout}
3
\newcounter{pseudo}
4
\renewcommand{\thefigure}{\thepseudo.\arabic{figure}}
5
\newenvironment{writefigure}{%
6
\ifnum\value{chapter}=\value{pseudo}\else
7
\setcounter{pseudo}{\value{chapter}}
8
\addtostream{tryout}{\protect\stepcounter{chapter}}
9
\addtostream{tryout}{\protect\addtocounter{chapter}{-1}}
10
\addtostream{tryout}{%
11
\protect\setcounter{pseudo}{\thechapter}}
12
\fi
13
\addtostream{tryout}{\protect\begin{figure}}
14
\writeverbatim{tryout}}%
15
{\endwriteverbatim\finishwritefigure}
16
\newcommand{\finishwritefigure}{%
17
\addtostream{tryout}{\protect\end{figure}}}
18
\newcommand{\printfigures}{%
19
\closeoutputstream{tryout}%
20
\input{\jobname.fig}%
21
}
Theabovecodeshouldbeeitherputinthepreambleorinaseparatepackagefile.
Thefirstfourlinesofthecodeperformtheinitialsetupdescribedearlier.Lines1and2
setupforoutputtingtoafile
\jobname.fig
,whichiswherethefigureswillbecollected.
Lines3and4createthenewcounterweneedandchangetheconstructionofthefigure
number.Therestofthecodedefinesanewenvironment
writefigure
whichistobeused
insteadofthe
figure
environment.Itwritesitscontentouttothe
tryout
stream.
Inline6acheckismadetoseeifthecurrentvaluesofthe
chapter
and
pseudo
coun-
tersarethesame; nothingisdoneiftheyare. . Iftheyaredifferent,itmeansthatthisis
thefirstfigureinthechapterandwehavetoputappropriateinformationintothefigure
file.Line7setsthe
pseudo
countertothevalueofthe
chapter
counter(ifthereisanother
writefigure
inthechapteritwillthenskipoverthecodeinlines7to11).Thenextlines
put(whereNisthenumberofthecurrentchapter):
\stepcounter{chapter}
\addtocounter{chapter}{-1}
\setcounter{pseudo}{N}
intothefigurefile.Steppingthechapternumber(byone)resetsthefollowingfigurenum-
ber,andthensubtractingonefromthesteppednumberreturnsthechapternumbertoits
originalvalue.Finallythecounter
pseudo
issettothenumberofthecurrentchapter.
Line13puts
290
15.4. Files
\begin{figure}
intothefigurefile,andline14startsthe
writeverbatim
environment.
Fortheendofthe
writefigure
environment(line15),the
writeverbatim
environ-
mentisendedandafterthatthe
\finishwritefigure
macroiscalled.Thisisdefinedin
lines16and17,andsimplywrites
\end{figure}
outtothefigurefile.The
\endwriteverbatim
,andanyotherkindof
\end...verbatim
,
commandisverysensitivetoanythingthatfollowsit,andinthiscasedidnotliketobe
immediatelyfollowedbyan
\addtostream{...}
,butdidnotminditbeingwrappedup
inthe
\finishwritefigure
macro.
The
\printfigures
macrodefinedinthelastthreelinesofthecodesimplyclosesthe
outputstreamandtheninputsthefiguresfile.
Asanexampleofhowthisworks,ifwehavethefollowingsourcecode:
\chapter{The fifth chapter}
...
\begin{writefigure}
%% illustration and d caption
\end{writefigure}
...
\begin{writefigure}
%% another r illustration and d caption
\end{writefigure}
thenthefigurefilewillcontainthefollowing(shownverbatiminthe
fboxverbatim
en-
vironment).
\stepcounter{chapter}
\addtocounter{chapter}{-1}
\setcounter{pseudo}{5}
\begin{figure}
%% illustration and caption
\end{figure}
\begin{figure}
%% another illustration and caption
\end{figure}
15.4.5 Example:questionsandanswers
Textbooksoftenhavequestionsattheendofachapter. Sometimesanswersarealsopro-
videdattheendofthebook,orinaseparateteachersguide. Duringthedraftstagesof
suchabookitisusefultokeepthequestionsandanswerstogetherinthesourceandpaper
drafts,onlyremovingorrepositioningtheanswerstowardstheendofthewritingprocess.
Thisexampleprovidesanoutlineformeetingthesedesires.Forpedagogicalpurposes
Iusea
\label
and
\ref
techniquealthoughtherearebettermethods. Theexamplealso
showsthatnoteverythingworksasexpected—itisareasonablyaccuraterenditionofthe
processthatIactuallywentthroughindesigningit.
Firstweneedacounterforthequestionsandwe’lluseanenvironmentforquestions
asthesemaybeofanycomplexity.Theenvironmenttakesoneargument—auniquekey
tobeusedina
\label
.
291
15. B
OXES
,
VERBATIMSANDFILES
\newcounter{question} \setcounter{question}{0}
\renewcommand{\thequestion}{\arabic{question}}
\newenvironment{question}[1]%
{\refstepcounter{question}
\par\noindent\textbf{Question \thequestion:}\label{#1}}%
{\par}
Ihaveused
\refstepcounter
toincrementthecountersothatthe
\label
willreferto
it,andnotsomeexternalcounter.
Wewilluseafile,called
\jobname.ans
tocollecttheanswersandthiswillbewritten
tobyastream. Thereisalsoaconveniencemacro,
\printanswers
,fortheusertocallto
printtheanswers.
\newoutputstream{ansout}
Amatchingenvironmentforanswersisrequired.Theargumenttotheenvironmentis
thekeyofthequestion.
Indraftmodeitissimple,justtypesettheanswerandnoneedtobotherwithanyfile
printing(rememberthat
\ifdraftdoc
is
true
foradraftmodedocument).
\ifdraftdoc
% when n in draft mode
\newenvironment{answer}[1]%
{\par\noindent\textbf{Answer \ref{#1}:}}%
{\par}
\newcommand{\printanswers}{}
\else
% when n not in n draft mode
Infinalmodethe
answer
environmentmustwriteitscontentsverbatimtothe
ans
file
forprintingby
\printanswers
.Dealingwiththeseinreverseorder,thisisthedefinition
of
\printanswer
whennotindraftmode.
\newcommand{\printanswers}{%
\closeoutputstream{ansout}
\input{\jobname.ans}}
Now for the trickybit, the
answer
environment. Firstdefineanenvironment t that
makessureouroutputstreamisopen,andwhichthenwritestheanswertitletothestream.
\newenvironment{@nswer}[1]{\@bsphack
\IfStreamOpen{ansout}{}{%
\openoutputfile{\jobname.ans}{ansout}%
}%
\addtostream{ansout}{\par\noindent\textbf{Answer \ref{#1}:}}%
}{\@esphack}
Themacros
\@bsphack
and
\@esphack
areLaTeXkernelmacrosthatwillgobbleextrane-
ousspacesaroundtheenvironment. Inotherwords,thisenvironmentwilltakenospace
inthetypesetresult.The
\IfStreamOpen
macroisusedtotestwhetherornotthestream
isopen,andifitisn’tthenitopensit. Theanswertitleisthenwrittenouttothestream.
Nowwecandefinethe
answer
environmentsothatitscontentsgetwrittenoutverbatim.
\newenvironment{answer}[1]%
{\@bsphack\@nswer{#1}\writeverbatim{ansout}}%
292
Documents you may be interested
Documents you may be interested