Example: If you prefer “fig.” instead of “figure” in USenglish, you may achieve this using:
\renewcaptionname{USenglish}{\figurename}{fig.}
If you want the same change not only in USenglish but also in UKenglish, you
do not need an additional:
281
Chapter 12.
\renewcaptionname{UKenglish}{\figurename}{fig.}
but can simply extend the language list :
\renewcaptionname{USenglish,UKenglish}{\figurename}{fig.}
You can extend the language list in the same manner by american,
australian
, british, canadian, and newzealand.
Since KOMA-Script 3.12
v3.12
you do not need to delay the definition or redefinition until
\begin{document}
using \AtBeginDocument any longer because scrbase does the delay au-
tomatically for (re)definitions in the document’s preamble. Additionally, scrbase tests if a
redefinition should be made in \extraslanguage instead of \captionslanguage and does
so automatically. The new star variants of the commands always use \extraslanguage . So
redefinition of language dependent terms for packages like hyperref that use \extraslanguage
should work as expected by the user.
Language dependent terms usually defined by classes and language packages are listed and
described in
table 12.1
.
Table 12.1.: Overview of language dependent terms of usual language packages
\abstractname
heading of the abstract
\alsoname
“see also” in additional cross references of the index
\appendixname
“appendix” in the heading of an appendix chapter
\bibname
heading of the bibliography
\ccname
prefix heading for the distribution list of a letter
\chaptername
“chapter” in the heading of a chapter
\contentsname
heading of the table of contents
. . .
282
Chapter 12.
Table 12.1.: Overview of usual language dependent terms (continuation)
\enclname
prefix heading for the enclosure of a letter
\figurename
prefix heading of figure captions
\glossaryname
heading of the glossary
\headtoname
“to” in header of letter pages
\indexname
heading of the index
\listfigurename
heading of the list of figures
\listtablename
heading of the list of tables
\pagename
“page” in the pagination of letters
\partname
“part” in the heading of a part
\prefacename
heading of the preface
\proofname
prefix heading of mathematical proofs
\refname
heading of the list of references
\seename
“see” in cross references of the index
\tablename
prefix heading at table captions
283
Chapter 12.
12.5. Identification of KOMA-Script
Package scrbase may be used independent of KOMA-Script with other packages and classes.
Nevertheless, it is a KOMA-Script package. For this, scrbase also provides commands to
identify KOMA-Script and to identify itself as a KOMA-Script package.
\KOMAScript
This command only sets the word “KOMA-Script” with sans-serif font and a little bit tracking
for the capitals. By the way: All KOMA-Script classes and packages define this command, if
it has not been defined already. The definition is robust using \DeclareRobustCommand.
\KOMAScriptVersion
KOMA-Script defines the main version of KOMA-Script in this command. It has the form
“date version KOMA-Script”. This main version is same for all KOMA-Script classes and the
KOMA-Script packages that are essential for the classes. Because of this, it may be inquired
after loading scrbase, too. For example, this document has been made using KOMA-Script
version “2016/06/14 v3.21 KOMA-Script”.
12.6. Extension of the L
A
TEX Kernel
Sometimes the L
A
TEX kernel itself provides commands, but lacks other, similar commands that
would often be useful, too. Some of those commands for authors of packages and classes are
provided by scrbase.
\ClassInfoNoLine{class name }{information }
\PackageInfoNoLine{package name }{information }
For authors of classes and package the L
A
TEX kernel already provides commands like
\ClassInfo
and \PackageInfo to write information. together with the current line number,
into the log-file. Besides \PackageWarning and \ClassWarning to throw warning messages
with line numbers, it also provides \PackageWarningNoLine and \ClassWarningNoLine for
warning messages without line numbers. Nevertheless, the commands \ClassInfoNoLine
and \PackageInfoNoLine for writing information without line numbers into the log-file are
missing. Package scrbase provides them.
\l@addto@macro{command }{extension }
The L
A
TEX kernel already provides an internal command \g@addto@macro to extend the def-
inition of macro \command by extension globally. This may be used only for macros that
have no arguments. Nevertheless, sometimes a command like this, that works locally to a
group instead of globally, could be useful. Package scrbase provides such a command with
\l@addto@macro
. An alternative may be usage of package etoolbox, which provides several of
such commands for different purposes (see [
Leh11
]).
284
Chapter 12.
12.7. Extension of the Mathematical Features of ε-TEX
ε
-TEX, that is meanwhile used by L
A
TEX and needed by KOMA-Script, provided with
\numexpr
, an extended feature for calculation of simple arithmetic with TEX counters and
integers. The four basic arithmetic operations and brackets are supported. Correct rounding
is done while division. Sometimes additional operators would be useful.
\XdivY{dividend }{divisor }
\XmodY{dividend }{divisor }
Having a division with remainder command
v3.05a
\XdivY
gives the value of the integer quotient,
with command \XmodY giving the value of the remainder. This kind of division is defined:
dividend
= divisor · integer quotient + remainder
with dividend and remainder are integer, remainder is greater or equal to divisor, and divisor
is a natural number greater than 0.
The value may be used for assignment to a counter or directly in the expression of \numexpr.
For output the value as an Arabic number has to be prefixed by \the.
285
Chapter 13.
Control Package Dependencies with scrlfile
The introduction of L
A
TEX2ε in 1994 brought many changes in the handling of L
A
TEX exten-
sions. Today the package author has many macros available to determine if another package
or class is employed and whether specific options are used. The author can load other packages
or can specify options in the the case that the package is loaded later. This has led to the
expectation that the order in which package are loaded would not be important. Sadly this
hope has not been fulfilled.
13.1. About Package Dependencies
More and more frequently, different packages either newly define or redefine the same macro
again. In such a case the order in which a package is loaded becomes very important. For the
user it sometimes becomes very difficult to understand the behaviour, and in some cases the
user wants only to react to the loading of a package. This too is not really a simple matter.
Let us take the simple example of loading the package longtable with a KOMA-Script doc-
ument class. The longtable package defines table captions very well suited to the standard
classes, but the captions are totally unsuitable for documents using KOMA-Script and also
do not react to the options of the provided configuration commands. In order to solve this
problem, the longtable package commands which are responsible for the table captions need
to be redefined. However, by the time the longtable package is loaded, the KOMA-Script class
has already been processed.
Until the present, the only way for KOMA-Script to solve this problem was to delay the
redefinition until the beginning of the document with help of the macro \AtBeginDocument.
If the user wants to change the definitions too, it is recommended to do this in the preamble
of the document. However, this is impossible since later at \begin{document} KOMA-Script
will again overwrite the user definition with its own. Therefore, the user too has to delay his
definition with \AtBeginDocument.
Actually, KOMA-Script should not need to delay the redefinition until \begin{document}.
It would be enough to delay exactly until the package longtable has been loaded. Unfortunately,
the L
A
TEX kernel does not define appropriate commands. The package scrlfile provides redress
here.
Likewise, it might be conceivable that before a package is loaded one would like to save the
definition of a macro in a help-macro, in order to restore its meaning after the package has
been loaded. The package scrlfile allows this, too.
The employment of scrlfile is not limited to package dependencies only. Even dependencies
on any other file can be considered. For example, the user can be warned if the not uncritical
file french.ldf has been loaded.
Although the package is particularly of interest for package authors, there are of course
286
Chapter 13.
applications for normal L
A
TEX users, too. Therefore, this chapter gives and explains examples
for both groups of users.
13.2. Actions Prior to and After Loading
scrlfile can execute actions both before and after the loading of files. In the commands used
to do this, distinctions are made made between general files, classes, and packages.
\BeforeFile{file }{instructions }
\AfterFile{file }{instructions }
The macro \BeforeFile ensures that instructions are only executed before the next time
file
is loaded. \AfterFile works in a similar fashion, and the instructions will be executed
only after the file has been loaded. If file is never loaded then the instructions will
never be executed.
In order to implement those features scrlfile redefines the well known L
A
TEX command
\InputIfFileExists
. If this macro does not have the expected definition then scrlfile is-
sues a warning. This is for the case that in future L
A
TEX versions the macro can have a
different definition, or that another package has already redefined it.
The command \InputIfFileExists is used by L
A
TEX every time a file is to be loaded.
This is independent of whether the actual load command is \include, \LoadClass,
\documentclass
, \usepackage, \RequirePackage, or similar. Exceptionally, the command
\input foo
loads the file foo without utilizing \InputIfFileExists. Therefore, one should always use
\input{foo}
instead. Notice the parentheses surrounding the file name!
\BeforeClass{class }{instructions }
\BeforePackage{package }{instructions }
These two commands work in the same way as \BeforeFile. The only difference is that the
document class class and the L
A
TEX package package are specified with their names and not
with their file names. That means that the file extensions .cls and .sty can be omitted.
287
Chapter 13.
\AfterClass{class }{instructions }
\AfterClass*{class }{instructions }
\AfterClass+{class }{instructions }
\AfterClass!{class }{instructions }
\AfterAtEndOfClass{class }{instructions }
\AfterPackage{package }{instructions }
\AfterPackage*{package }{instructions }
\AfterPackage+{package }{instructions }
\AfterPackage!{package }{instructions }
\AfterAtEndOfPackage{package }{instructions }
The commands \AfterClass and \AfterPackage work in the same way as \AfterFile. The
only difference is that the document class class and the L
A
TEX package package are specified
with their names and not with their file names. That means that the file extensions .cls and
.sty
can be omitted.
The starred versions are a little bit different. They execute the instructions not only at
next time that the class or package is loaded, but also immediately if the class or package has
been loaded already.
The plussed
v3.09
version executes the instructions after loading of the class or package has
been finished. The difference to the starred version is only valid, if loading of the class or
package already started but has not been finished yet. Nevertheless, instructions will be
executed before the instructions of \AtEndOfClass or \AtEndOfPackage when loading of the
class or package has not been finished already.
If a class uses \AtEndOfClass or a package uses \AtEndOfPackage to execute instruc-
tions after the class of package file has been loaded completely, and if you want to execute
instructions
after the instructions of these commands, you may use the exclamation mark
version, \AfterClass!
v3.09
respectively \AfterPackage!.
If you want to do this only in the case the class or package will be loaded later, and if you
want to execute instructions outside the context of the class or package, that will be loaded,
you may use \AfterAtEndOfClass
v3.09
for classes and \AfterAtEndOfPackage for packages.
Example: In the following, an example for class and package authors shall be given. It shows
how KOMA-Script itself employs the new commands. The class scrbook contains:
\AfterPackage{hyperref}{%
\@ifpackagelater{hyperref}{2001/02/19}{}{%
\ClassWarningNoLine{scrbook}{%
You are using an old version of hyperref package!%
\MessageBreak%
This version has a buggy hack at many drivers%
\MessageBreak%
causing \string\addchap\space to behave strange.%
\MessageBreak%
Please update hyperref to at least version
6.71b}}}
288
Chapter 13.
Old versions of the hyperref package redefine a macro of the scrbook class in such
a way that does not work with newer KOMA-Script versions. New versions of
hyperref desist from making these changes if a new KOMA-Script version is de-
tected. For the case that hyperref is loaded at a later stage, therefore, the code in
scrbook verifies that a acceptable hyperref version is used. If not, the command
issues a warning.
At other places in three KOMA-Script classes the following can be found:
\AfterPackage{caption2}{%
\renewcommand*{\setcapindent}{%
After the package caption2 has been loaded, and only if it has been loaded, KOMA-
Script redefines its own command \setcapindent. The exact code of the redefini-
tion is not important. It should only be noted that caption2 takes control of the
\caption
macro and that therefore the normal definition of the \setcapindent
macro would become ineffective. The redefinition improves the collaboration with
caption2.
There are however also useful examples for normal L
A
TEX user. Suppose a document
that should be available as a PS file, using L
A
TEX and dvips, as well as a PDF file,
using pdfL
A
TEX. In addition, the document should contain hyperlinks. In the list of
tables there are entries longer than one line. This is not a problem for the pdfL
A
TEX
method, since here hyperlinks can be broken across multiple lines. However, if a
hyperref driver for dvips or hyperTEX is used then this is not possible. In this case
one desires that for the hyperref setup linktocpage is used. The decision which
hyperref driver to use happens automatically via hyperref.cfg. The file has, for
example, the following content:
\ProvidesFile{hyperref.cfg}
\@ifundefined{pdfoutput}{\ExecuteOptions{dvips}}
{\ExecuteOptions{pdftex}}
\endinput
All the rest can now be left to \AfterFile.
\documentclass{article}
\usepackage{scrlfile}
\AfterFile{hdvips.def}{\hypersetup{linktocpage}}
\AfterFile{hypertex.def}{\hypersetup{linktocpage}}
\usepackage{hyperref}
\begin{document}
\listoffigures
\clearpage
\begin{figure}
\caption{This is an example for a fairly long figure caption, but
which does not employ the optional caption argument that would
289
Chapter 13.
allow one to write a short caption in the list of figures.}
\end{figure}
\end{document}
If now the hyperref drivers hypertex or dvips are used, then the useful hyperref
option linktocpage will be set. In the pdfL
A
TEX case, the option will not be set,
since in that case another hyperref driver, hpdftex.def, will be used. That means
neither hdvips.def nor hypertex.def will be loaded.
Furthermore, the loading of package scrlfile and the \AfterFile statement can be writ-
ten in a private hyperref.cfg. If you do so, then instead of \usepackage the macro
\RequirePackage
ought be used (see [
Tea06
]). The new lines have to be inserted directly
after the \ProvidesFile line, thus immediately prior to the execution of the options dvips
or pdftex.
\BeforeClosingMainAux{instructions }
\AfterReadingMainAux{instructions }
Package authors often want to write something into the aux-file after the last document page
have been shipped out. To do so, often
\AtEndDocument{%
\if@filesw
\write\@auxout{%
\protect\writethistoaux%
}%
\fi
}
is used. Nevertheless this is not a real solution of the problem. If the last page of the document
already have been shipped out before \end{document}, the code above will not result in any
writing into the aux-file. If someone would try to fix this new problem using \immediate just
before \write, the inverse problem would occur: If the last page was not shipped out before
\end{document}
the \writethistoaux would be written into aux-file before ship-out the last
page. Another often seen suggestion for this problem therefore is:
\AtEndDocument{%
\if@filesw
\clearpage
\immediate\write\@auxout{%
\protect\writethistoaux%
}%
\fi
}
This suggestion has a disadvantage again: The ship-out of the last page has been enforced by
the \clearpage. After that, instructions like
290
Chapter 13.
\AtEndDocument{%
\par\vspace*{\fill}%
Note at the end of the document.\par
}
would not any longer output the note at the end of the last page of the document but at the
end of one more page. Additionally \writethistoaux would be written one page to early into
the aux-file again.
The best solution for this problem would be, to write to the aux-file immediately after the
final \clearpage, that is part of \end{document}, but just before closing the aux-file. This
is the purpose of \BeforeClosingMainAux:
\BeforeClosingMainAux{%
\if@filesw
\immediate\write\@auxout{%
\protect\writethistoaux%
}%
\fi
}
This would be successful even if the final \clearpage inside of \end{document} would
not really ship-out any page or if someone have had used \clearpage in the argument of
\AtEndDocument
.
Nevertheless there one important limitation using \BeforeClosingMainAux: You should
not use a typeset instruction inside the instructions of \BeforeClosingMainAux! If you
miss this limitation the result would be as unpredictable as the results of the problematic
suggestions using \AtEndDocument upward.
Command \AfterReadingMainAux
v3.03
actually executes the instructions just after closing
and input of the aux-file inside of \end{document}. This will make sense only in some cases,
e. g., to show statistic information, that will be valid only after input of the aux-file, or to
write such information into the log-file, or to implement additional rerun requests. Typeset
instructions are even more critical inside these instructions that inside the argument of
\BeforeClosingMainAux
.
13.3. Replacing Files at Input
All previous sections in this chapter describe commands to execute instructions before or after
input of a file, class, or package. Package scrlfile also provides commands to input another
file, class, or package instead of the one, that has been declared.
\ReplaceInput{source file name }{replacement file name }
This
v2.96
command defines a replacement for the file of the first argument: source file name ,
by the file of the second argument: replacement file name . If L
A
TEX will be instructed to
291
Chapter 13.
input the file with source file name at any time afterward, the file with the replacement
file name
will be input instead. The replacement definition will be valid for all files, that the
user will input with \InputIfFileExists and for all files, that will be input with a command,
that uses \InputIfFileExists internally. To do so, scrlfile redefined \InputIfFileExists.
Dostları ilə paylaş: |