LATEX&friends course in Helsinki a TEX/LATEX enthusiast’s view

Gaetano Zanghirati University of Ferrara, Italy in cooperation with DOMAST Doctoral School in Mathematics and Statistics

Helsinki, May 2019 Cross-references

LATEX’s cross-referencing mechanism is very powerful almost anything that is numbered can easily referenced (sections, figures, formulas) LATEX automatically takes care of numbering, updating it whenever necessary the commands to be used are independent of what has to be referenced \label{name} assigns the mnemonic name name of your choice to the element that has to be referenced (as long as it has a number associated with it) \ref{name} returns the right numbering associated to name, while \pageref{name} returns the corresponding page number the parameter name does not appear in the output document, but if you reference a nonexistent name, then LATEX print “??” where such a reference command appear and issues the warning LaTeX Warning: There were undefined references

A course on LaTeX&friends .:. G. Zanghirati & DOMAST .:. Helsinki, May 2019 Cross-references

Cross-referencing is a two steps mechanism: 1 LATEX store in an external auxiliary file( .aux) the label with the right number to be used 2 in the next compilation, LATEX reads in the right numbering from the auxiliary file and substitute the calling \ref command with such a number every time the auxiliary file is changed, LATEX displays in the console (and write out in the log file) the warning LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right

the \pageref command can be used to help the reader identify the place where the referenced element is. For instance See table~\ref{tab:countries} on page~\pageref{tab:countries}

the \label command must be put immediately after the number-generating command that refers to the element

A course on LaTeX&friends .:. G. Zanghirati & DOMAST .:. Helsinki, May 2019 Cross-references

All letters and punctuation marks can be used to form the name of a label best practice: differentiate the kind of element with the name itself. Common choices: prefix meaning prefix meaning ch: chapter eq: equation sec: section lst: code listing subsec: subsection itm: enumerated list item fig: figure alg: algorithm tab: table app: appendix

Suggestion Avoid using numbers within labels! It’s much better to describe what the object is about: if you change the order of the objects, there is no need to rename all labels and their references!

A course on LaTeX&friends .:. G. Zanghirati & DOMAST .:. Helsinki, May 2019 Cross-references

the amsmath package introduces specialized cross-referencing commands: \eqref typesets parenthesized numbers \tag{eqnnum} allows to manually set equation numbers to the eqnnum text string you want to appear in the document. It is normally better to use labels!. Example: \tag{\ref{eqn:before}}. \numberwithin{cntrA}{cntrB} replaces the simple cntrA by cntrB.cntrA \numcases, \subnumcases for the cases env. the command \vref from varioref package has a different output according to the context, i.e., to the relative position of element and reference: if both are in the same page, it behaves exactly as \ref; if they appear in different pages, it automatically adds the page number (if they are far away from each other), or a string such as “on the facing page”, “on the next page”, “on the previous page” (if the two pages are contiguous).

A course on LaTeX&friends .:. G. Zanghirati & DOMAST .:. Helsinki, May 2019 Cross-references

The hyperref package provides the command \autoref: it creates a reference with additional text corresponding to the target?s type, and all of which will be a hyperlink. Example: \autoref{sec:intro} create a hyperlink to \label{sec:intro} and, if the pointed element is Section 3.4, the hyperlink would contain the text “section 3.4”, or similar \autoref* produces an unlinked prefix there exists also a cleveref package which In the preamble, they must be loaded in the sequence varioref, hyperref and cleveref to avoid conflicts

A course on LaTeX&friends .:. G. Zanghirati & DOMAST .:. Helsinki, May 2019 Managing bibliographies

Managing references and citations is a relevant task There are two components: the source of information and the way they are displayed in the final document The source is essentially a set of “objects” that are mentioned somewhere in the document. Each one of these objects has attributes that may or may not be relevant to typeset The displayed aspect is the visual look of the data, that is the style used to typeset the selected attributes of each object LATEX allows two ways of management embedded system: all references data are part of the document source and you explicitly take care of the visual aspect of each single object you want to appear the final document database-enabled system: the raw data are stored in one (or more) external file(s) in a form of database items, one for each object, while the look they will have in the final document is determined by “bibliography style” specifications, in the form of TEX/LATEX commands coded in a dedicated file. A course on LaTeX&friends .:. G. Zanghirati & DOMAST .:. Helsinki, May 2019 Managing bibliographies

The embedded system: the bibliography data must be put inside a thebibliography environment each object is introduced in the source code by a \bibitem command, followed by the respective attributes and the style to be used to show them the argument of \bibitem is a unique alphanumerical key that will be used to cite the reference:

Modern \LaTeX{} is described in Modern LATEX is described in [1]. \cite{LatexCompanion2004}. \begin{thebibliography}{9} \bibitem{LatexCompanion2004} References Frank Mittelback, Michael Goossens, [1] Frank Mittelback, Michael \textit{The \LaTeX Companion}, Goossens, The LATEXCompanion, Second Edition, Addison-Wesley, Second Edition, Addison-Wesley, Massachusetts, 2004. Massachusetts, 2004. \end{thebibliography}

A course on LaTeX&friends .:. G. Zanghirati & DOMAST .:. Helsinki, May 2019 1 Managing bibliographies

The embedded system: the list of references will appear in the final document exactly where you put the environment the mandatory argument of \begin{thebibliography} tells LATEX how wide the item label will be when printed. However, that the number itself is not the parameter, but the number of digits is. the bibitem key is a mnemonic label consisting of any sequence of letters, numbers and punctuation symbols (although not a comma) various strategies suggest how to assemble this mnemonic label from the reference data and there are also automatic tools available, that can do the job for you the \cite{key} command cite a reference in the text the \cite command accepts an optional argument specifying some details of that particular reference useful for the reader Example: \cite[chapter 13, pag.~757]{LatexCompanion2004} → [1, chapter 13, pag. 757]

A course on LaTeX&friends .:. G. Zanghirati & DOMAST .:. Helsinki, May 2019 Managing bibliographies

multiple consecutive citations are obtained by adding more than one reference key inside the same \cite command: \cite{LatexCompanion2004,Lamport1994} → [1, 2] which is different from \cite{LatexCompanion2004} \cite{Lamport1994} → [1] [2] surely, the thebibliography environment can be put in a dedicated .tex file and \inputed in the source, in the point where the bibliography have to appear, but. . .

When is the embedded system useful? If you are writing only one or two documents and aren?t planning on writing more on the same subject for a long time. It saves the time of creating a database of references that you are never going to use again.

A course on LaTeX&friends .:. G. Zanghirati & DOMAST .:. Helsinki, May 2019 Managing bibliographies

The Database-enabled system: it is a much more powerful and flexible solution it uses the auxiliary tool calledB IBTEX, (bundled with LaTeX) BIBTEX has been succeeded by BibLATEX, which is configurable and customizable within LaTeX syntax BIBTEX provides for the storage of all references in an external, “flat-file” database with extension .bib (BibLATEX too) This database can be referenced in anyLATEX document, and citations made to any record it contains. This is often more convenient than embedding them at the end of every document written a “centralized” bibliography source can be linked to as many documents as desired: “write once, read many!” Of course, bibliographies can be split over as many files as one wishes: this is very useful! Example: a database players.bib dedicated to players biographies and clubs.bib dedicated to teams club history documents

A course on LaTeX&friends .:. G. Zanghirati & DOMAST .:. Helsinki, May 2019 Managing bibliographies

There are several different ways to format lists of bibliographic references and the citations to them in the text List styles are specified in special .bst files The citation styles consist of two parts: the format of the abbreviated citation( i.e., the marker that is inserted into the text to identify the entry in the list of references) the format of the corresponding entry in the list of references, which includes full bibliographic details two main types for abbreviated citations: numbered: are numbered consecutively in order of appearance in the list of references. Consist in Arabic numerals in parentheses, square brackets, superscript, or a combination thereof (Vancouver system) textual: use the author surname and (usually) the year as the abbreviated form of the citation, which is normally fully or partially enclosed in parenthesis (Harvard system) A course on LaTeX&friends .:. G. Zanghirati & DOMAST .:. Helsinki, May 2019 Managing bibliographies

Citations styles are usually selected by options to dedicated packages, such as natbib style name author name format reference format sorting plain Homer Jay Simpson #ID# by author unsrt Homer Jay Simpson #ID# as referenced abbrv H. J. Simpson #ID# by author alpha Homer Jay Simpson Sim95 by author abstract Homer Jay Simpson Simpson-1995a acm Simpson, H. J. #ID# authordate1 Simpson, Homer Jay Simpson, 1995 apacite Simpson, H. J. (1995) Simpson1995 named Homer Jay Simpson Simpson 1995 Syntax in the preamble: \usepackage[options]{natbib}

A course on LaTeX&friends .:. G. Zanghirati & DOMAST .:. Helsinki, May 2019 Managing bibliographies

Citation styles compatible with pkgnatbib: plainnat, abbrvnat, unsrtnat, apsrev, rmpaps, IEEE-tranN, achemso, rsc,... Natbib’s customization options: Option Meaning round, square, Parentheses () (default), square brackets [], curly braces or curly, angle angle brackets < > colon, comma multiple citations separated by semi-colons (default) or commas authoryear, author year style citations (default), numeric citations or numbers, super superscripted numeric citations sort, multiple citations are sorted into the order in which they sort&compress appear in the references section or also compressing multiple numeric citations where possible longnamesfirst the first citation of any reference will use the starred variant (full author list), subsequent citations will use the abbreviated et al. style sectionbib for use with the chapterbib package. Redefines \thebibliography to issue \section* instead of \chapter* nonamebreak keeps all the authors’ names in a citation on one line to fix some hyperref problems. Causes overfull hboxes

A course on LaTeX&friends .:. G. Zanghirati & DOMAST .:. Helsinki, May 2019 Managing bibliographies

The main citation commands simply add a t for “textual” or p for “parenthesized”, to the basic \cite command \citet, \citep Natbib by default will compress references with three or more authors to the concise version “Fisrt Surname et al.”. By adding an asterisk (*) list all authors associated with that citation. There are some other specialized commands that Natbib supports The \bibpunct allows change display settings (preamble): \bibpunct{(}{)}{;}{a}{,}{,} arg 1: symbol for the opening bracket arg 2: symbol for the closing bracket arg 3: symbol separating multiple citations arg 4: a letter: n for numerical style, s for numerical superscript style, any other letter for author-year style arg 5: punctuation to appear between the author and the year (in parenthetical case only) arg 6: punctuation between years, in multiple citations when there is a common author, e.g., (Chomsky 1956, 1957). For an extra space use {,~}.

A course on LaTeX&friends .:. G. Zanghirati & DOMAST .:. Helsinki, May 2019 Managing bibliographies

ABIBTEX database is stored as a .bib file .bib files are plain text files and can be viewed and edited easily the structure is a record of named fields each entry begins with the declaration of the reference type, in the form of @type (@article, @BOOK, @InProceedings,...) the first field is the unique citation key next fields contain data for that particular reference, in the form fieldname = "..." or fieldname = {...} Example: @article{greenwade93, author ={Greenwade, George D.}, title ={The{C}omprehensive{T}ex{A}rchive{N}etwork ({CTAN})}, year ={1993}, journal ={TUGBoat}, volume ={14}, number ={3}, pages ={342--351} }

A course on LaTeX&friends .:. G. Zanghirati & DOMAST .:. Helsinki, May 2019 Managing bibliographies

There are many record types, each one with its own fields (see manuals): @article, @book, @booklet, @conference, @inbook, @incollection, @inproceedings, @manual, @mastersthesis, @misc, @phdthesis, @proceedings, @techreport, @patent, @electronic, @Unpublished

There are many databases over internet freely available for download! Most search engines offer citations already formatted in BIBTEX format

There are a lot of free and non-free tools that help maintain the .bib database: BibDesk, BibSonomy, BibTeXSearch, Bibtex Editor, , CiteULike, DokuWiki3, Ebib, JabRef, KBib, KBibTeX, , , , . . . To use the database in the document use the \bibliographystyle and \bibliography commands: \bibliographystyle{plain}% no.bst extension \bibliography{mybib1,mybib2,...,mybibN}% no.bib, no white spaces

A course on LaTeX&friends .:. G. Zanghirati & DOMAST .:. Helsinki, May 2019 Managing bibliographies

You need to compile the database with BIBTEX: pfdlatex myMainSource myMainSource pfdlatex myMainSource pfdlatex myMainSource

1 the first command compile myMainSource.tex, 2 the second one compiles myMainSource.aux by reading the .bib files mentioned in \bibliography command and produces the myMainSource.bbl file 3 the third and fourth commands re-compile myMainSource.tex by reading myMainSource.aux and myMainSource.bbl files and the .bst style file specified in the \bibliographystyle command

To customize the bibliography appearance use Makebst (at the console) To localize the bibliography load the babelbib package

A course on LaTeX&friends .:. G. Zanghirati & DOMAST .:. Helsinki, May 2019 Managing bibliographies

BibLATEX is intended as a full replacement for BIBTEX it is more configurable in its output provides a multitude of new styles (for output) and fields (for the database) it would deserve much more attention, but it seems still less known to the large majority of publishers however, you can safely use it for your own documents, since the database structure of the .bib files is the same as that of BIBTEX to its comprehensive documentation on CTAN

A course on LaTeX&friends .:. G. Zanghirati & DOMAST .:. Helsinki, May 2019