<<

LYX, The Other Way of Writing 2018 Edition

One of the best tools to work with the most powerful document editor

Ricardo G. Berlasso

https://frommindtotype.wordpress.com/ LATEX and derivatives such as XƎTEX have the great advantage of their power and the big problem, at least in their “pure” form, of their difficult “learning curve.” LYX solves the difficulty of using LATEX without compromising its power, providing a robust and easy-to-use program that will satisfy both, new and veteran users. In this book we explore the power of LYX, LATEX, XƎTEX and OpenType, showing how far we can go. LYX, The Other Way of Writing

Speak documentclass And Enter

Ricardo Berlasso

2018 Edition © 2018 Ricardo Gabriel Berlasso This book is distributed under a Creative Commons license Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) (http://creativecommons.org/licenses/by-sa/4.0/)

Attribution: Youmust give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.

ShareAlike: If you remix, transform, or build upon the material, you must distribute your contribu- tions under the same license as the original.

No additional restrictions: You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.

Any mark mentioned in this book belongs to its owner.

The latest version of this book can be found at: https://frommindtotype.wordpress.com/lyx-book/ Contents

Introduction 1 To whom is this book addressed? ...... 1 The structure of this book ...... 3 A bit of history ...... 4 Minimal requirements ...... 5 Conventions used in this book ...... 6 Links to have at hand ...... 7

I The foundations 9

1 Defining LATEX 11 1.1 What is LATEX ...... 11 1.2 LATEX as a tag language (almost…) ...... 13 1.3 Document classes ...... 15 1.4 “Building” the document ...... 16 1.5 And OpenType came to LATEX ...... 17

2 Why is LYX so special 19 2.1 The “WYSIWYM” concept ...... 21 2.2 and “formats” ...... 23 2.3 Main LYX features ...... 23 2.4 How is working with LYX ...... 24

I II Index

2.5 LyX for LATEX fundamentalists ...... 25 2.6 When yes, when not ...... 26

II Let’s start to set up things 29

3 The graphical interface of LYX 31 3.1 General description ...... 31 3.2 Keyboard shortcuts ...... 34 3.3 Many documents, in many ways ...... 35

4 Building documents 37 4.1 Working with LYX ...... 37 4.1.1 General format of the document ...... 37 4.1.2 Text ...... 41 4.1.3 Lists ...... 42 4.1.4 Math ...... 43 4.1.5 Tables ...... 44 4.1.6 “Boxes” ...... 46 4.1.7 Figures, tables and other “floats” ...... 48 4.1.8 Cross-references ...... 48 4.1.9 Indexes ...... 50 4.1.10 Generate a “dynamic” PDF: the Hyperref package 52 4.1.11 Navigate and organize the document ...... 54 4.2 Appendixes ...... 56 4.3 Bibliography ...... 56 4.4 Language ...... 57 4.4.1 New in 2.3: “dynamic and ‘nested’ quotation marks” 57 4.4.2 Dictionaries ...... 58 4.4.3 Babel vs. Poliglosia ...... 60 4.4.4 Babel options in LATEX/LYX ...... 60 4.5 Import and export documents ...... 61 4.6 Copy information from other programs ...... 61 4.7 Change tracking ...... 62 4.8 Working with “branches” ...... 62 4.9 Master documents ...... 65 Index III

III Beyond the basic settings 67

5 Some commands 69 5.1 The LATEX preamble ...... 69 5.2 The TEX box ...... 70 5.3 A matter of “size” ...... 71 5.4 A matter of “shape” (typographical) ...... 71 5.5 Numbers! ...... 73 5.6 Reconfigure! ...... 74

6 LYX, OpenType and 75 6.1 OpenType for the predefined ...... 76 6.2 Defining a font family ...... 78 6.3 OpenType for the entire document ...... 78 6.4 Different fonts for different “shapes” ...... 79 6.5 Different OpenType options for each “shape” ...... 80 6.6 Apply a stylistic set to a particular character ...... 81 6.7 OpenType for math, 1: -math ...... 82 6.8 OpenType for math, 2: mathspec ...... 84 6.9 Line spacing ...... 86 6.10 Hyphenation ...... 88 6.11 Micro-typography ...... 89 6.11.1 What micro-typography means and its use .... 89 6.11.2 How to apply micro-typography ...... 91 6.12 Sub- and superscripts ...... 91

7 Footnotes and endnotes 95 7.1 Notes numbers without superscript ...... 95 7.2 Footnotes in columns ...... 96 7.3 Footnotes without breaks ...... 96 7.4 Restart footnote numbering on each ...... 96 7.5 “Numbering” footnotes with symbols ...... 97 7.6 Change the footnote font ...... 98 7.7 Endnotes ...... 98 7.8 An extra: notes ...... 99 IV Index

8 Modules, local format and math macros 101 8.1 Modules ...... 101 8.2 Create new instructions ...... 103 8.3 Create character styles in LYX ...... 104 8.4 Paragraph environment? ...... 107 8.5 Math macros ...... 108

9 Numbered lists 113 9.1 Modify particular lists ...... 113 9.2 Change all lists in the document ...... 114

10 About the Table of Contents and other Indexes 117 10.1 Short titles ...... 117 10.2 Partial TOCs for each chapter ...... 117 10.3 Correct the spacing in lists of figures and tables ...... 118 10.4 Avoid dotted lines in indexes ...... 119 10.5 Some (few) words about alphabetical indexes ...... 119

11 Headings 121 11.1 Rename the “Part” and “Chapter” environments ..... 121 11.2 Number chapters with Roman numerals ...... 122 11.3 Make the chapter start at any page ...... 122 11.4 Avoid page breaks at the beginning of a chapter ...... 122 11.5 Change the format of titles in LYX documents ...... 123 11.5.1 The packages needed ...... 123 11.5.1.1 xcolor ...... 124 11.5.1.2 titlesec ...... 124 11.5.2 A complete example ...... 124 11.6 Restart the numbering after a “Part” ...... 126

12 Headers and footers, and page styles 129 12.1 Preparations ...... 129 12.2 The fancyhdr package ...... 130 12.3 An example ...... 132 12.4 Create and use page styles ...... 133 12.5 First page of the chapter ...... 136 Index V

12.6 Blank ...... 137 12.7 The page style for the “Part” environment ...... 138

13 Drop Caps and similar topics 141 13.1 Something traditional ...... 141 13.2 Be careful with the number of lines! ...... 143 13.3 A variant: a “raised” ...... 144 13.4 A challenge ...... 144 13.5 An alternative: first line of paragraph in .... 145

14 Figures and other floats 147 14.1 Adjust the size of inserted images ...... 147 14.1.1 Manual adjustment of image size ...... 147 14.1.2 Automatically adjust the size ...... 149 14.1.3 Size of the image in the editing window ..... 151 14.1.4 To avoid repetition: graphic groups ...... 151 14.2 “Wrapped” figures ...... 151 14.3 Center pictures or tables inside floats ...... 153 14.4 Setting the caption text formatting for all floats ...... 154 14.5 Rename floats ...... 155 14.6 Change the numbering scheme of figures and tables .... 155

15 Extras 157 15.1 Describe keys and menus: the menukeys package ..... 157 15.1.1 What is menukeys ...... 158 15.1.2 Using menukeys in LYX ...... 159 15.2 Side captions for figures/tables ...... 161 15.3 Adding a new float ...... 162 15.4 Colored boxes ...... 163 15.5 Things I have not talked about ...... 164 15.5.1 BibLATEX support ...... 164 15.5.2 Presenting code with listings ...... 165 15.5.3 PDF forms ...... 165 15.5.4 Sweave and ...... 165 15.5.5 Computer Algebra Systems ...... 165 15.5.6 And much, much more ...... 165 VI Index

IV Appendixes 167

A All about 169 A.1 Fonts used in this book ...... 169 A.2 More about ...... 170

B Local Layout 171

CLATEX preamble 175

D Other formats... and a greeting 179 D.1 Other formats used in this book ...... 179 D.2 And yes, direct formatting ...... 180 D.3 Final greetings ...... 181 Introduction

Many years ago there was a free digital magazine in Spanish about free soft- ware called “Begins.” For that magazine I wrote several articles, some about 1 Writer, some about LYX. Over time, both sets of articles became books, and now those books are being translated into English. As you will soon realize, I am not a native English speaker. If you find any (or many!) error(s) in this text, please let me know! You can use the contact form on my personal blog for that https://frommindtotype.wordpress.com/contact/ And of course, you can always find the latest, hopefully corrected, ver- sion of this book at https://frommindtotype.wordpress.com/lyx-book/

To whom is this book addressed?

To say that LYX is a “graphical front-end for LATEX” is an understatement. LYX is a powerful document processor build upon LATEX (and deriva- tives: in this book I will talk a lot about XƎTEX) that offers its users a variety of graphic and command line tools that will satisfy even the most demand- ing users. In principle (life is always complicated) it is possible to use LYX with- out knowing anything about what is behind it, but of course that would

1. https://elpinguinotolkiano.wordpress.com/domando-al-escritor-2/ https://elpinguinotolkiano.wordpress.com/latexxetexlyx/

1 2 Introduction

be a serious limitation because, as we will see all over across this book, this program offers far more than a few buttons and menus. LYX can help both, new users who have never used LATEX before as well as experts that have no problem “coding” their documents:2 new users will find that their introduction to the LATEX world will be much easier com- pared with other alternatives, while advanced users will have no problem implementing their old tricks in LYX. And here is the main of this discourse: sooner rather than later something about LATEX we must learn, like it or not. In fact, many LYX tools, such as the creation of character styles or new environments, require a fairly in-depth knowledge of LATEX. So, is it worth the effort? As always in life, it depends. LATEX is an incredible powerful system, but “great power carries great responsibilities.” And in this case, the responsibility of the user is to learn how to use the system. If someone provides us with the base documenclass (the template) and we only need to feed the content, LATEX is really easy to use: commands are simple and easy to understand, the document structure is logical and clear, mathematical expressions flow naturally, numbering and cross-referencing are easy, etc. And everything becomes idyllic with a program like LYX, where we do not have to worry about forgotten brackets and the code do not bother us when we are writing. If nobody gives us the documentclass but we like one of the predefined ones, without needing to change anything, LATEX is still quite simple. A new user might have some trouble trying to create special pages (acknowl- edgments, copyright, etc.), but it will not be a problem to solve everything with a couple of question on the Internet. If we have to go further... Everything depends on how far we need to go. Clearly LYX will help us on our journey, but it is also clear that it cannot do everything for us: LATEX is too big.

2. TEX, the basis over which LATEX is built, is a Turing complete language: basically, any proce- dure that can be written as an algorithm can be implemented in TEX. I mean, nobody says it is easy, but at least it is possible. Introduction 3

To give you an idea, the LATEX preamble for this document has more than 120 lines of code, the “local format” (style definitions) has more than 90 lines and many places in this book needed the use of code (through the famous “TEX boxes” that we will use repeatedly in this book). It is also necessary to pay attention to the packages used because some of them may conflict with each other: for instance, titlesec, a package used to format headings has problems with tocloft, a package to change index formatting.3 LATEX is so powerful that is an universe in itself: a sometimes contradic- tory universe in which it is not always easy to know the rules. LATEX gives us the power to do anything about formatting. It is not only its versatility to write mathematical expressions that makes it essential in technical documents, LATEX gives us the power to seek the beauty of the document itself: advanced typography, simplicity in figure and table han- dling, everything is in our hands. And that means that the question “is worth the effort to learn LATEX” is not correct, we must ask ourselves if we are interested in achieving what LATEX can provide and if we are willing to make the effort to learn new things. And that is something that only you, dear reader, can answer. I invite you to come with me in this typographical adventure, perhaps your ideas will be clarified during the trip. Do not be afraid to experiment: being LYX , you only need to install it and see if it catches you.

The structure of this book

The book is divided into three parts plus some appendixes. Wewill go from the simplest to the more complex, starting with a light introduction to what LATEX is, followed by a description of the LYX interface and how to work with this program, before ending with advanced topics about document building.

3. Most likely, this is because titlesec comes with titletoc, another package that can be used to change index formatting. The problem is that titletoc is not as powerful as tocloft. 4 Introduction

As we already mentioned, some graphic tools in LYX require to know something about LATEX, so their explanation will be delayed to the more “advanced” part. An example of this is the creation of character styles: only after learning how to apply different typographical options “by hand,” of being able to create new instructions and LATEX commands, of being con- fident with the “preamble,” only then can we go to the “local layout” and create our styles, which can then be used with a simple right click. All this will make some topics seem more complicated of what they re- ally are, but there is no alternative: before running, we have to learn how to walk.

A bit of history

Following with the joke on the book cover we could write The doors of LYX, Lord of Texts. Speak, documentclass, and enter. I, , made them, the community made them grow. But before arriving here, many things were necessary. Let’s have an quick and oversimplified review of the main ones.

1977 When received the test for the second edition of The Art of Computer Programming, he found it ter- rible. At that time he had already begun to take an interest in digital typography systems, so the poor presentation of his book pushed him to create his own typographical system, TEX. Many years were needed before the system was ready for general use (many more of what he predicted), but everything started at that very moment.

1985 LATEX was created by Leslie Lamport as a way to simplify the use of TEX through a series of macros that perform specific tasks, such as the creation of footnotes, headings, etc., along with tools to compile the documents.

1995 Matthias Ettrich began to develop an user interface to LATEX called Lyrix. Soon after, the project changed its name to avoid conflicts with a commercial now discontinued. Introduction 5

The new name, LYX, comes from the file name extension used by Lyrix. The following year, Matthias Ettrich started the project for which he is best known: KDE.

2004 XƎTEX is released, a LATEX-based system with Unicode support and the ability to use modern typographical technologies such as OpenType, AAT and Graphite.

2011 As of version 2.0.0, LYX offers direct support for XƎTEX, LuaTEX and XHTML.

And the rest is history.

More information: https://en.wikipedia.org/wiki/TeX https://en.wikipedia.org/wiki/LaTeX https://en.wikipedia.org/wiki/LyX https://en.wikipedia.org/wiki/XeTeX https://en.wikipedia.org/wiki/Donald_Knuth https://en.wikipedia.org/wiki/Leslie_Lamport https://en.wikipedia.org/wiki/Matthias_Ettrich http://www.lyx.org/misc/archaeology/ http://tolkiengateway.net/wiki/Doors_of_Durin

Minimum requirements

I will assume that the reader has at least the same tools that I used to write this book. These tools are:

• LYX 2.3 or later

• ALATEX distribution equivalent to TEXLive 2017 or later • (Optional) Pandoc 1.17 or later

I will also assume that the reader knows, or at least has who to ask, how to install those programs and how to add packages to a LATEX distribution. 6 Introduction

That means I will take it for granted that the reader knows how to use a computer. And most importantly, I will assume the reader’s willingness to try new things and explore for themselves the topics introduced in this book. Here you will not find detailed guides on how to do this or that, or exercises to get used to the program: for that there is already excellent doc- umentation included in LYX. Because of this and even if many topics will be covered more or less exhaustively, many others will only be presented, al- lowing the curious reader to get used to the documentation and go beyond the predefined options. The best way to learn is to do!

Conventions used in this book

The paths to the different menus will be indicated with a particular format.4 For example, the path to reach the “LATEX preamble” (Document, then Set- tings and finally LaTeX Preamble) will be indicated as:

Document Settings LaTeX Preamble

Keyboard shortcuts will also have a particular format.5 For example the key combination “Ctrl” and “E” will be presented as

Ctrl E

while “Alt” with “P”, then “2” will be presented as:

Alt P , then 2 .

I am aware that Mac’s operative system requires adapting those short- cuts, but I do not have access to that system, so I cannot provide the equiv- alences. To indicate code or package names a mono-spaced font will be used:

4. Courtesy of the menukeys package. 5. Also courtesy of menukeys package. We will describe this package in section 15.1.2. Introduction 7

\usepackage{emptypage} titlesec

To indicate addresses, either on the internet or in the file system (mainly to indicate where a package documentation is) a sans font will be used:

https://www.lyx.org/ /usr/share/texmf/doc/latex/fancyhdr/

About that last point: I write from a Linux6 system and that means the addresses that I will provide are those of my system. If the reader uses a dif- ferent system or something different from TEXLive, those addresses should be adapted, but it should be simple to do it. For those with the PDF version of this document, the internet links will be blue while the links within the document (table of contents, cross- references, etc.) will be shown in cyan. Each link will be “active” on the PDF: one click will take the reader to the linked element, either opening the internet browser on the linked page or moving through the document.

Links to have at hand

LYX project page is in https://www.lyx.org/ The wiki https://wiki.lyx.org/ To get support on LYX you have the mailing lists. To subscribe it is enough to write an e-mail to [email protected] After confirming the subscription, it is enough to write to [email protected] It is important to keep in mind that the mailing list is set to “reply to sender,” so to keep a conversation there you must remember to add the address of the list. I forgot it many times...

6. Or GNU/, if you prefer. Or GNU/BSD/MIT/Apache/MPD/etc./Linux, to be more pre- cise. I use openSUSE Leap. 8 Introduction

The traffic on the list is low, but answers are fast! Just remember: it is a public mailing list, so your e-mail address will be known to everyone! The bug tracking system is https://www.lyx.org/trac/wiki/BugTrackerHome As we advance in this book, we will need more and more information about LATEX and the best place to obtain documentation for any package (other than the local installation) is the CTAN(Comprehensive TEX Archive Network) repository: http://ctan.org/ And, of course, the place where every answer about LATEX can be found is TEX-LATEX Stack Exchange: https://tex.stackexchange.com/ If nobody there knows how to solve it, it is impossible. And since al- most nothing is impossible in LATEX, there you will find the answer. Part I

The foundations Where we define the general concepts on which all the rest is based

On the shoulders of giants Chapter 1 Defining LATEX

As we already pointed out in the introduction, in principle it is not necessary to know LATEX (or XƎTEX) to use LYX: the latter offers a really nice graphical interface for the first one. But it is also true that knowing something, that being aware of what LATEX is and how it works will give us the power to control the appearance of our documents to a level that is unreachable for other text processors. And that is the reason why this book begins with a light introduction to LATEX, that being clear about what is going on “under the hood” will allow us to go further. In the third part of this book, starting with the chapter 5, we will come back to these topics: to enter the “advanced” part we will need to know how to write some code. But for now it is enough to superficially look at some basic concepts. Let’s start with it.

1.1 What is LATEX

The fundamental idea behind LATEX and derivatives such as XƎTEX (which is not always achieved, everything must be said) is to separate the content from the format. To indicate a chapter heading we only say “chapter” (using the LATEX language, of course) without considering typography, size, numbering... All

11 12 What is LATEX those details are automatically handled by LATEX. We just have to worry about the text itself! The format is defined in a separated file called documentclass, a file that is “called” in our document, along with other formatting indications, on what is known as the “LATEX preamble.” In this sense, LATEX works as an interpreted programming language in which instructions are given to the system, which then “builds” the docu- ment. These instructions can be written in a conventional text file, so, in principle, you do not need a special program to write a LATEX document, although it is highly recommended to use one. And for that we have the protagonist of this book: LYX. This double structure, file with content + file with format definitions is at the same time the point of greatest strength and the main problem of LATEX and derivatives. The greatest strength, because it is possible to change the documentclass without problems, because having the styles separated from the content do- nates greater “robustness” to our documents, because if someone else pro- vides the documentclass our only task is to write because the document struc- ture is standard and easy to understand. The biggest problem, because defining a documentclass it is incredible difficult, someone else must provide it, because the use of a different type- face needs some work, because trying to change the format from what is indicated in the documentclass could result in a lot of extra work. Fortunately, any standard LATEX distribution such as TEXLive is packed with many documentclasses that cover almost any need, and with a little work we can always customize everything. The problem for many new users is that LATEX is closer to a program- ming language than to a traditional text composition system: the “common user” (that is, the non-academic user who does not need to write complex mathematical formulae) tends to feel intimidated by LATEX. After all, even if LATEX instructions are simple, they are still instructions. But do not worry that, as we will see, this problem is not (at least, not quite) real. Defining LATEX 13

1.2 LATEX as a tag language (almost…) The most famous tag language is maybe , so if you know something about that you can understand what we are talking about: any element in a LATEX document is “surrounded” by tags that define the properties we want for that element. For example, if we want to write a famous mathematical expression like1 2 2 퐸2 = (푚푐2) + (푝푐) , to do that “in-line” (that is, within a paragraph), in LATEX we write

$E^{2}=\left(mc^{2}\right)^{2}+ \left(pc\right)^{2}$

whereas if we want the expression in its own paragraph, with a number that automatically changes when other expressions are included, such as

2 2 퐸2 = (푚푐2) + (푝푐) (1.1) then we write

\begin{equation} E^{2}=\left(mc^{2}\right)^{2}+ \left(pc\right)^{2} \end{equation}

On the other hand, if we are not interested in the number we can use

\[ E^{2}=\left(mc^{2}\right)^{2}+ \left(pc\right)^{2} \]

LATEX also uses instructions that are more similar to “functions” (hence the “almost”). For example, to indicate a section title we write

\section{This is the title of the section}

1. No, it is not wrong: the other one is wrong (or at least incomplete). 14 LATEX as a tag language (almost…)

Many instructions can be nested, so if we need a mathematical expres- sion within the title of the section we write

\section{The relativistic energy: $E^{2}=\left(mc^{2}\right)^{2}+ \left(pc\right)^{2}$}

It is also possible to “give a name” to an equation in order to reference it later. For this purpose we can use the instruction

\label{name}

With all this, a typical “pure” LATEX document would look similar to the following example (plus some other things that define the document class and that will be considered later):

\begin{document} \section{The relativistic energy: $E^{2}=\left(mc^{2}\right)^{2}+ \left(pc\right)^{2}$} The famous relationship between energy, mass and the speed of light squared, $E=mc^{2}$ is just a particular case of a more general and important expression, which can be seen, numbered and in all its glory, here: \begin{equation} E^{2}=\left(mc^{2}\right)^{2}+ \left(pc\right)^{2} \label{eq:Einstein} \end{equation} The equation \ref{eq:Einstein} gave many headaches to the fathers of quantum mechanics. \end{document} Defining LATEX 15

Let me insist that with LYX it is not necessary to write all this, we are only presenting how everything works “under the hood.” As you can see, within the code a “cross-reference” was made (like this one: 1.1) to the numbered equation using the command

\ref{name}

It is important to keep in mind that both \label and \ref can be used for far more than the “calling” of equations. These instructions are “smart” and if we place \label close to a section title (or a figure or table), \ref can understand where the referenced target is located and display it as it should. From this simple, and clearly incomplete, example it is evident that while we are writing a LATEX document we only have to worry about the content, not about its shape: even the numbering of the sections and the equations (and the figures and tables) is automatically performed by the system. Another thing that is done automatically in LATEX and that is a real bless- ing in complex documents is the positioning of figures and tables: not only they change page when necessary, but also the text around them automati- cally flow to fill any possible gap in the page. Yes, you read it right, without effort from the writer2 disappear in LATEX the eternal struggles with empty spaces when a figure moves to the next page, because the system, using criteria that are easy to customize, works so that everything is perfect.

1.3 Document classes

I can hear you: everything in the previous section is fine, that thing of think- ing more about the content than about the shape is super cool, but sooner or later I will have to worry about how my document will look like. How do I decide the typeface, its size and everything else? As we already mentioned, LATEX takes the definition for each style from a documentclass, a special file where all the formatting stuff is set. For exam- ple, the size and typeface that should be used when the \section command is applied is defined in the documenclass.

2. We will see later the limits of all this, that in life nothing is perfect, but do not worry that they are not problematic. 16 “Building” the document

To select a documentclass, such as article, and a language for that docu- ment, such as Spanish, we need to write at the very beginning (before the \begin{document}):

\documentclass[spanish]{article}

Creating a documentclass from scratch is really difficult and requires ad- vanced knowledge of LATEX, but fortunately you do not need to do so: every modern LATEX distribution comes preloaded with tons of ready-to-use docu- mentclasses and the CTAN repository offers many more. This fact, together with the possibility of “fine tuning” our documents by changing their de- fault values gives us the power to build the desired format without major problems. For example, if instead of using the default A4 paper for the “article” documentclass we want to use A5, the previous command changes to:

\documentclass[a5paper,spanish]{article}

In this part of the document before the \begin{document}, a part called LATEX preamble, it is possible to define many things. From the chapter 5 we will make extensive use of the preamble, so for now I will stop talking about code. But just for now.

1.4 “Building” the document

As this book is an introduction to a graphical tool to manage LATEX, I will not enter the jungle of technical details on how a document is built: LYX does everything for us, so I will only give you the basic ideas. Our document is so far just a collection of LATEX instructions that must be compiled (usually, more than once) to obtain the final result. This com- pilation is performed by calling a program called “” or another closely related to it (pdflatex, xelatex, etc.) with a series of parameters among which must be, obviously, the name and location of our file. LATEX then gener- ates a .dvi or . file that can be visualized or printed with or any other program and where all the definitions of the documentclass are im- plemented. It is also possible, by using the hyperref package, to obtain a Defining LATEX 17

“dynamic” document where links, both within the document or to another documents or websites, are active (I will come back to this point bellow).

1.5 And OpenType came to LATEX Something we have not talked about yet is how to choose typefaces. This omission is due to two reasons, the first of which being that making that selection from LYX is far easier than with “pure” LATEX. The second reason is “heavier:” LATEX uses its own typography system, a system that is not only completely incompatible with all other systems, but is also really complicated. LATEX typefaces are not called by family or style, but by file name.3And to make matters worst, in its “traditional” form LATEX do not support Uni- code: this means that getting support for languages other than English can be a real challenge. There are LATEX variants that solve both problems, specially the Unicode support. In this book I will focus on the project that is perhaps the most mature of all: XƎTEX. XƎTEX, initially developed by the people of Sil International precisely to provide support for non-western languages, is a LATEX variant that not only provides Unicode support, but also permits the use of system fonts. In fact, XƎTEX is one of the few free systems providing full OpenType sup- port,4 allowing the use of all the advanced features of this technology, such as automatic substitution (typographical ligatures, for example), the use of real Smal Caps, real indexes... anything provided by the font. XƎTEX calls fonts on a different way than LATEX, but since we have not talked about how the last one does it, I will not enter in details about how the former does it. At least not at this point: we will come back to this topic briefly in chap- ter 4 and in great depth (fill your oxygen tanks) in chapter 6.

3. Before some “LATEX purist” protests, yes, I know there are packages to select groups of fonts more easily. But in truth this reinforces what I am saying: managing fonts “by hand” is complicated. 4. LibreOffice surprised me by providing a decent support for OpenType since version5.3. also supports this technology since version 1.5. 18 And OpenType came to LATEX

Well, enough of “theoretical basis” and all that “under the hood” stuff: this book is about LYX, so in the next chapter we will begin to talk about its possibilities. Take a little more coffee, dear reader, we are on track to this adventure. Chapter 2 Why is LYX so special

There is a long war between those who believe that the best way to create documents is with a text editor, as is done with “pure” LATEX, and those who believe that nothing is better than a good graphical interface with menus and buttons everywhere like... well, sure you know at least one example of such program. Those who advocate for the text-based editing say, and usually they are right, that when you know the right codes it is far easier to just type than to go from one place to another looking for the right button, and that in graphical editors you spend more time looking for the right function than using it. To this the defenders of graphical tools say, and usually they are right, that remembering an infinitude of commands, no matter how simple they are, implies an effort that most of the time cannot be justified and that the “learning curve” of a graphical program is always gentler than the learning curve of a text-based system. In this war there is a third faction that claims that both groups are a bunch of idiots and that nothing is better than a good keyboard shortcut. To that both groups reply, and usually they are right, that relying on all those keyboard shortcuts require, both in the fingers and in the memory, the skills of a virtuoso pianist. Well, LYX solves this ancient war in the most elegant way possible. Those “heavy” actions that need to be carried out only once per doc- ument (selecting the documentclass, typefaces, page size and margins, etc.)

19 20

Figure 2.1: The math editor in action are handled through menus. Those particular actions that need to be carried out every now and then in particular documents (change the numbering of the index pages, set up special pages) can be handled through code. Finally, and here lies the beauty of the program, for everything else you can use either code, menus/buttons or keyboard shortcuts. Exactly: LYX offers the best of all worlds, providing happiness to every kind of user. Consider for example the figure 2.1. Here we see LYX’s math editor, but the concept is valid for other func- tions too. As you can see, there is a toolbar with buttons to insert fractions, for example. But if instead of pressing a button we start to type the instruc- tion \frac,LYX not only understands what we are writing but also offers a menu with possible instructions that can be completed from what we have written so far: \frac for fractions, \frak to use the typeface or \framebox to insert a box around some text. Let’s focus for a moment on \frac: if after completing the instruction we press the space bar, the command will be replaced by a real fraction with two “input fields” waiting for the numerator and the denominator. Now, if instead of typing \frac (or using the corresponding button) we press Why is LYX so special 21

Alt M , followed by F , we will get the exactly same result. And that is how everything works: if you type \sqrt, or use the button with the square root, or the combination Alt M followed by , you will always get an empty square root ready to receive an argument. As we already said, this versatility is not limited to equations. For exam- ple, in normal text we can use the box in the upper left corner of the toolbar area to select the Section “environment” (or Chapter, or special ... the available environments depend on the selected documentclass) or use the shortcut Alt P , followed by 2 . As you can see, the LYX interface gives us the possibility to work in three modes: text, menu/buttons and keyboard shortcuts. Whatever makes the user happy.

2.1 The “WYSIWYM” concept

What LYX shows when editing a document is not the same you will get when the document is finally compiled, but it gives us a clear idea of what the document means. In fact, LYX does not show page breaks: they are useless when working on the content. It generate them on compiling, though, so don’t worry. Also, you will not see the LATEX code on the edit window: all those com- mands, \documentclass, \begin{document}, \end{document}, etc., are all “hidden” and managed by LYX without direct writer intervention. Even the titles of chapter and sections are presented as real titles (but with a dif- ferent format) and not with the instruction \section. There are a couple of thing new LYX users need to get used to:

• There are no page rulers.

• If we press the space bar twice, the second time it will be ignored. The same applies to the key: spaces are automatically handled by styles, the author does not need to worry about them.

• The is used only to move between parts of the document (parts of a mathematical expression, table cells...). 22 The “WYSIWYM” concept

Figure 2.2: Choosing the documenclass

• Everything related to spacing, indents, text format, header and footer content, positioning of figures and tables... everything is managed by LYX in an automated way according to the and the document- class selected in Document Settings Document Class .

As you can see in figure 2.2, we have many document classes available and we can always get more from our LATEX distribution. We also have, in other menus, many ways to “customize” our selection, changing, for example, how paragraph are separated (indentation or vertical space), the size of the pages and their margins, the “float” positioning, numbering, etc. The avail- able options depends upon the selected document class, but there are always so many options that even the most detail-lover user will be satisfied. Also, the way in which every part of the document is built is not gov- erned solely by those options, we can always make a “fine-tuning” in differ- ent parts of the document: from the Edit ... menu it is possible to change the settings for a particular paragraph, a single word or a special page, while Why is LYX so special 23

from the Insert ... menu it is possible to insert manual page breaks, special spaces between words or paragraph, whatever is necessary. Ah! Ctrl B toggles bold while Ctrl E toggles italics: at least that is (almost) the same as always.

2.2 Fonts and “formats”

Among the many things you can find in Document Settings (, Margins, Language…) we have two entries of great interest for this book: Fonts and Formats. There we can set everything for LYX to use XƎTEX (or LuaTEX, but we will not use that option here) when building our documents. If we select Fonts Use non-TeX fonts (via XeTeX/LuaTeX) we can choose system fonts instead of LATEX fonts, but it is also a good idea to explicitly tell the system that XƎTEX has to be used when compiling the document: under Formats Default output format we can choose «PDF (XeTeX)».

2.3 Main LYX features

LYX is based on libraries and, therefore, can work on many platforms. LYX can load several documents simultaneously, opening them in “tabs” in the same way Firefox opens several web pages. It is also possible to use a “split screen” to show documents side by side (or one on top of the other, we will come back to that later). The program remembers in which part of the document we were when it was closed, so it will go back to that point when it is reloaded. It also pro- vides a panel that shows the document structure, which can be activated from View Outline pane . This pane works like an “index,” which allows us not only to quickly reach a point but also to easily change the order and “level” of any heading (“demoting” a section to subsection, for example). The “Keep” check box is interesting to prevent the “tree” of levels from clos- ing when we double-click a higher level. We will come back to this point in the section 4.1.11. There is also a system to track changes, which gives us the possibility to record, accept or reject changes, facilitating teamwork in a single document 24 How is working with LYX

(we will talk a little about this in section 4.7). LYX can use for real time spell check and has a thesaurus that can use dictionaries from LibreOf- fice (section 4.4.2). It gives us the ability to work in several languages within the same document. It offers an incredible simple and robust way to work with master documents (section 4.9)... Something important to remember is that LYX works without prob- lems with Unicode, so even in the case we decide not to use XƎTEX, we will not have any problem when inserting special symbols or accented char- acters: LYX will translate everything so that LATEX understands it without trouble. Wemust bear in mind that the images are not embedded in the LYX files, they are only linked, and the original files remain in their original locations. In the case we need to work with the same file in different systems (each PhD student knows that they need to work even more at home than in the office) it takes a little more work to keep everything synchronized. To easy the task of moving a project to a different system, it is possible to export a compressed “package” as a tar.gz file containing the LYX document and every picture and related files: File Export LyX Archive (tar.gz) . At desti- nation, we just have to decompress the file in an empty folder to be ready to keep working.

2.4 How is working with LYX We will come back to all this in great detail from next chapter, but let’s now make a quick review of the “working method” you need in LYX. I have already pointed out that figure and table positioning is done au- tomatically. To that, you need to first insert an appropriate “float” ( Insert Float ) and inside it place the figure or table along with its caption. These floats, like all footnotes and other special elements, are presented as a red “box,” an inset, with a label indicating what kind of element they are. These insets have the capability to “close,” showing only the label, when we do not need to see their content: this can be achieved for a particular inset with a simple click over its label, or globally with View Close all insets . Many in- sets offer a contextual menu to set up their properties. At this point it is important to keep in mind that LATEX can work mainly Why is LYX so special 25 with images (EPS), while XƎTEX or pdfTEX only with PDF images... but do not worry, LYX uses different external libraries to accept almost any type of image, converting them to the appropriate for- mat when needed. In general, if we need high quality , using vector formats like EPS, PDF or SVG we will obtain the best results, but any type of bitmap image (png, jpg, whatever) will work flawlessly. A fundamental concept in LYX is that of environment. Environments are used to distinguish between different parts of a document, for example, separating the title of the chapter from the normal text that follows it, and can be assigned with the menu that can be found on the left of the first tool- bar (or with the corresponding keyboard shortcut...), just below the File menu. The available environments depend on the selected document class. For example, when writing an article or a letter, it makes no sense to have Chap- ters, but in a book, it does. We have already introduced the different keyboard shortcuts offered by LYX. These keyboard shortcuts are of two kinds: “direct” ones such as the combinations Ctrl M or Ctrl M used to introduce a mathematical expression, or the “key sequences” such as the already mentioned Alt M followed by F to introduce a fraction, or Alt M , then G followed by a letter (a, b...) to insert a Greek character (훼, 훽...). As we already mentioned, the main environments also have assigned keyboard shortcuts, which start with Alt P and end on a number from 0 to 6 (or a “b,” or an “e,” try them to see what they provide!). It is important to keep in mind that some keyboard shortcuts may not work on some document classes. The last important step in LYX’s workflow is clearly the document com- pilation. Surely you have already seen the toolbar just below the environ- ment menu: from left to right we have “View,” “Update,” “View master document”... the first two buttons will be the most used by far, specially if you are a new LYX user.

2.5 LyX for LATEX fundamentalists

Even if LYX uses its own XML-based file format to store the work, do not worry, LATEX fans, the conversion to LATEX format is always perfect and for 26 When yes, when not a good reason: LYX always converts to LATEX format every time the docu- ment gets compiled so that is something that must work. That means that if for any reason someone needs to obtain an human-readable LATEX file, it is enough to go to File Export . In LYX, it is possible to insert code not only in mathematical mode. To work with code outside the math mode we have the TEX button (keyboard shortcut: Ctrl L ) that opens a special “box” where we can write our gor- geous code. For example, if we use one of the “book” document classes, we can insert our red box with the command

\frontmatter just before the index ( Insert List / TOC Table of Contents ) and a second box with

\mainmatter just after it to get the index pages numbered with Roman numerals, leav- ing the following pages with numerals that begin with 1 in the first chapter. We will come back to these (and other) topics. LYX gives us the ability to see the LATEX code in real time, either for the current paragraph or for the entire document, enabling the option View Code Preview Pane . Last, but not least, LYX offers a really easy way to edit the “LATEX pream- ble,” that is, (almost) all the code you can write between \documentclass and \begin{document} instructions that affect the general document be- havior: Document Settings LaTeX Preamble . The possibilities are almost unlimited and in the following pages we will see several examples.

2.6 When yes, when not

There is no such a thing as a perfect tool capable of doing anything, and clearly you do not use a screwdriver to nail a nail. LYX is powerful for an incredible variety of jobs, but it could be troublesome with others. Why is LYX so special 27

If we want to write a book, specially a technical one with math formulae, graphs, tables, etc., LYX is perfect (I am tempted to say essential), but if we need to create a poster, or a presentation, or design a magazine, or any other document that needs manual control of all its elements, it would be better to look for an alternative. Yes,it is possible to build a poster or a presentation with LYX (LATEX has many document classes for presentations), but it would not be difficult to find arguments to show that is not the right tool for the job. Despite being one of the oldest systems for text editing, LATEX and its derivatives continue to be one of the most powerful. Its limitations are few, and its benefits are excellent, specially thanks to LYX that facilitates all those annoying LATEX tasks like the document class selection, the creation of figures and tables, among other things. Even if some programs, specially Writer with its style-based philosophy and its good OpenTypesupport, are getting closer to the features offered by LATEX, they still have a long way to go, specially when we talk about complex technical documents. The broader user base for this system can be found among scientists (physicists, mathematicians, astronomers...) and engineering people, but it is not limited to that specialized group: LATEX or XƎTEX + LYX is open to anyone that have something to say through text and that want to obtain beautiful documents with (relatively) low effort. And here we arrive to a “philosophical” point: is there any reason to worry about the beauty of our documents? In fact, if we pick a book from the shelf of any bookstore, we will al- most certainty find a really poor presentation. And I am not only talking about a bad binding: even at this point of the century and the technology, many publishers still do not care about typographical ligatures, let alone contextual alternates or micro-typography. I have even seen books with an horrible !1 Each person has their own reaction to this sad reality. Mine is, so what? Is there any reason for me to worry about what other do not do? Of course not. I like a good looking and well presented text. I love typo-

1. https://en.wikipedia.org/wiki/Kerning https://www.xkcd.com/1015/ 28 When yes, when not graphical ligatures. I am a micro-typography fan. Why should I deprive my- self of using the powerful tools provided by LYX, XƎTEX and OpenType? Why should you deprive yourself, dear reader? If you do not want to renounce to dress with beauty the content of your documents, come with me, this trip has just begun. Part II

Let’s start to set up things Where we start working on LYX, basic to medium level

Don’t Panic! Chapter 3 The graphical interfaceY ofL X

LYX presents a typical interface of menus, toolbars and panels. But there is much more than meets the eye. Let’s see how it is built.

3.1 General description

As we said at the beginning, LYX’s interface seems quite “traditional:” a se- ries of menus on top followed by a couple of toolbars. With a right click on the toolbars we can modify the icon size and in the menu Tools Preferences there are several options to modify the general appearance of the program. But, of course, that is just the beginning, as you can see on figure 3.1. A very important space that tends to be overlooked is the thin bar bel- low the editing area. Here LYX presents really important information about what is “going on:”

• the function of the button on which the mouse pointer is located

• the formatting of the text on which the cursor is positioned

• the options we have to complete a keyboard shortcut

• the command that we just used from a menu

• compiler notifications (warnings, errors, etc.)

31 32 General description

Figure 3.1: LYX and its “multi-document” interface, showing the Outline panel and a dialog with the settings of an inserted image

Some of these features can be seen in figure 3.2. The combo Ctrl F gives us the basic “search & replace” tool, while Ctrl F offers a panel with more search options and the possibility to use regular expressions, search for math expressions, etc.

Note: I will not describe the search & replace tools. If you are interested, in section 6.13.3 of the manual found in Help User guide you can find everything on how to use it.

In the View ... menu we have several options. We will talk about the “Outline Pane” in section 4.1.11. The “Code Preview Pane” shows in real time the LATEX code generated by LYX. The “Messages Pane” shows the messages issued by LYX while working. We only need it if we find many errors when compiling the document. Under “Toolbars” it is possible to activate or deactivate different tool- bars. It is important to know that toolbars marked as “auto” are activated only when needed. An example of “auto” toolbars are those related to the equation editor. The graphical interface of LYX 33

Figure 3.2: The first screenshot presents the “status bar” displaying the func- tion of a button in the toolbar (note that if the action has an associated key- board shortcut, it will be shown there). The second screenshot show the text format information where the cursor is positioned. The third screenshot shows how, after issuing the first part of a keyboard shortcut sequence, all available options to “end” it are presented. In the last screenshot we see information about the action activated through a menu entry and that do not have (yet) an associated keyboard shortcut. 34 Keyboard shortcuts

3.2 Keyboard shortcuts

As we already mentioned, there are different kinds of keyboard shortcuts in LYX • The “traditional” ones, like Ctrl B to toggle bold. • Those that are “sequential,” where an “activation shortcut” is used followed by other keys or combination of keys. For example, Alt P followed by 2 to activate the “section” environment. As we have seen on figure 3.2, when we start a “sequential shortcut” the status bar offers the available options to complete it. Clearly, not all LYX functions have a keyboard shortcut assigned. Tocre- ate a new shortcut we have to go to Tools Preferences Editing Shortcuts : choosing a function from the list, with a click on “Modify” we can enter the chosen combination. And do not worry, LYX will warn us if the selected shortcut is already in use. Now, not all LYX functions are in the list, is it possible to create a key- board shortcut for those missing functions? Of course! Here we need to look, again, to the “status bar:” as we have also seen in the figure 3.2, when an action is issued from a menu, there we can find the “code” for that action.

Those “codes” are called “LYX functions.” It is possible to find a complete list of those functions in the menu Help LyX functions .

Suppose we want to create a sequential keyboard shortcut to insert the LYX logo. This logo is in Insert Special character Logos LyX logo . When we use it, we can see the following text in the status bar:

specialchar-insert lyx

This is what we need to create the new shortcut. Going back to Tools Preferences Editing Shortcuts , now we need to click on “New:” in “function” we write the code we found in the status bar, and in the corresponding box we introduce our keyboard shortcut, as you can see in the figure 3.3 This new shortcut is a tribute to the “sequential” shortcuts: Alt L and then the sequence L , Y and X . The graphical interface of LYX 35

Figure 3.3: Creating a new keyboard shortcut

3.3 Many documents, in many ways

LYX can work simultaneously with several documents, or multiple instances of the same document, either as tabs or in a “split screen” scenario. Each time we open a new document, it is added as a new tab. With the menu View Split View Into Left and Right Half / Upper and Lower Half it is possible to get two instances of the same document side by side or even one on top of the other, resulting in what we see in figure 3.4. It is important to keep in mind that if after dividing the view, say, ver- tically, we open another document, it will be added as a tab on the active view. I will let you play with the options. Just do not forget the right click on a tab! 36 Many documents, in many ways

Figure 3.4: Split screen + tabs: for all tastes Chapter 4 Building documents

In this chapter, we will quickly review (after all, we have the documenta- tion that comes with the program) how to create a simple document from scratch, select its type, browse it, and modify its content. We will present the basic tools offered by LYX and explain how to work with them. We will not enter the “LATEX details” yet (after all, we have the follow- ing chapters in this book), but what will be presented here is essential to understand how the program works.

4.1 Working with LYX

Creating a new LYX document is not different from other programs: we can use either File New , Ctrl N or the corresponding button in the toolbar. But as always, that is just the beginning. By default, a new LYX document uses the Article document class, which is perhaps the simplest document class offered by LATEX.

4.1.1 General format of the document Everything (OK, almost everything, we will come back to that later) what we need is in the menu Document Settings , as you can see in figure 4.1. In the first entry we can choose the document class. Unfortunately, the only way to know which document class we actually need is to create a test document using the different options, so I will not enter in the details about

37 38 Working with LYX

Figure 4.1: The Document Settings menu Building documents 39 how to choose the right one. But rest assured that not only you can change the selected document class later, but you can also adjust any detail of any document class! Just a general hint: there are a couple of document classes that are “re- peated,” offering a “standard” version and a second one with “extra font sizes.” For example, “Book (Standard Class)” and “Book (Standard Class with Extra Font Sizes).” Just forget the second one. We will come back to the “size” topic in the section 5.3, but let’s see for a moment why these two variants exist. If we go to the Fonts entry, under Base size we can find a series of possi- bilities. In addition to the Default option, there are three sizes for the text: 10 points (usually, the default option), 11 and 12, while classes with “extra sizes” offer, well, more options. For this book I used “Book (Standard Class)” choosing 11 points, but the other options are perfectly valid and some offer an almost unlimited number of possibilities, all of them clearly explained in the documentation that comes with each package. Back to the topic. In this first entry (Document Class) we have the op- tion “Suppress default date on front page” that does... exactly that: by de- fault all book document classes in LATEX add the date on the front page when the document is compiled, something that is not always desired. In fact, it is never desired. Well, checking that option as you can see in the screenshot, the date will not be added. Something important here is the section “Class Options.” In this box, we can pass any parameter to the document class to change the document behavior. For example, in the “book” document classes, when we choose to build a two-sided document, each chapter starts in an odd (right) page: if we do not want this limitation, we can add in Custom the instruction openany. As we already said, the available options depends on the document class in use, so you need to check the corresponding documentation. We will talk about “Modules” and “Local Layout” in chapter 8. The Font entry is, as it is easy to guess, the place where we can select the typefaces used by the document. The most important element here is the checkbox “Use non-TeX fonts (via XeTeX/LuaTeX)” because with this option we can use the system OpenType fonts instead of the LATEX fonts. 40 Working with LYX

We will come back to this complex, but interesting, topic in chapter 6. In a LATEX document we have three “font families:” the Roman, which is the base font, Sans Serif and Typewriter. As we have seen previously, the “base size” box gives us the possibility to choose the size for the base font, which is the Roman one. The size of the other two families is defined relatively to that base size: for example, in this book I used a scale of 80% for the typewriter font.1 The entries “Text Layout,” “Page Layout” and “Page Margins” are easy to use and understand... except for the Line spacing. But that is a really complex topic, so we will discuss it later, also in the chapter 6. Of all this I want to emphasize only one point, specially important for people coming from other programs such as Writer: in a LATEX/LYX docu- ment margins indicate the distance from the page border to the text area, but headers and footers do not belong to the text area and therefore they are introduced into the margins. For this reason, in “Page Margins” we have specific options to configure the position and height of headers and footers. We will talk about Language below. The Colors entry gives us the opportunity to select, well, the document colors (text, notes, page background). “Numbering & TOC” refers to how far we want to number the docu- ment structure. By default, Parts, Chapters, Sections, Subsections, and Sub- subsections are numbered, but nothing else. Also, the table of contents only include the numbered “levels.” Here, by sliding the controls on top, we can set what is numbered and what is not, or what is in the TOC and what is out of it. And so on... It is important to note that LYX has the concept of “template,” but it is a bit weaker than in other programs: as you can see in the menu File ... we can load a template, but there is no way to create one. In LYX templates are just normal documents, so if we want to reuse the options we select for a particular document we have two options: • The “Save as Document Defaults” button that we have in the doc- ument settings menu applies the selected options to all new docu- ments 1. DejaVu Sans Mono is “generous.” Building documents 41

• Save an empty document for each group of options (one for books, one for articles, etc.) and then call any of those documents from File New from Template

LYX comes with many predefined templates for special documents (spe- cific publications such as Springer and Scientific American, for example). One of these templates, PDF-cropped.lyx can be used to create a PDF from a math formula that can later be used in other applications. In the following chapters, we will talk about some of the other entries in the document settings menu: we will discuss the PDF Properties and Branches at the end of this chapter, Formats in the chapter 6 and the LATEX Preamble... in many different places.

4.1.2 Text

We now have the right fonts, page, margins... it is time to write! As we discussed in the introduction, a fundamental concept when us- ing LYX is the idea of environment: with the menu (or keyboard shortcut) to the left of the main toolbar, just below the “File” menu, we can apply to each paragraph the “function” it has: chapter, section, normal text, num- bered or bulleted list, etc. Everything is perfectly classified and easy to understand, so I will leave you with the task of playing a bit with these options to get used to them. The only important point to make is that the “unnumbered” (those with the asterisk) elements are not, by default, included in the TOC: we will come back to this in section 12.4. With all this the document will be perfectly structured and coherent. In LYX we have some predefined character styles: Ctrl E toggle the italic (the LATEX command LATEX \emph{}), Ctrl B toggle bold (the com- mand \textbf{}) while the sequence Alt C , then C toggle Small Caps (\noun{}). These three options can also be used from the toolbars.

Note: In addition to reapplying the “style” in order to deac- tivate it, we have the combination Alt C , then to return to the predefined format. 42 Working with LYX

For those rare situations where a bit of direct formatting is needed, the menus Edit Text Style Customized and Edit Paragraph Settings , both available from the right click, can help us. The way to introduce n- and m-dashes is quite simple: two dashes - -provides an n- –, while three dashes - - -gives an m-dash —.

4.1.3 Lists Directly from the toolbar or from the environment drop-down menu we can choose between Enumerate ( Alt P , then E ), Itemize ( Alt P , then I ), Labeling ( Alt P , then L ) and Description ( Alt P , then D ). The first two are the classical “numbered and bulleted lists” that other text processors insist we should use. These environments can be nested in different “levels,” and we can move from one level to the other using either the toolbars or the keyboard shortcuts Alt to go up one level and Alt to go down one level. Something like this: • First level

∘ Second level ∘ Another second level ⋄ Third level ∘ A new second level

• A new first level To exit the environment it is enough to select the Standard environ- ment or press twice. Both, labeling and description provide an environment in which the first word is the “term to be defined” and all the rest is the “definition.” The difference between both environments is only how the “keyword” and its description are separated. Just one point: if we need to have more than one word as “label” we need to “join” them with a protected space ( Ctrl ), so LYX considers them as a single word. In LYX it is quite easy to configure the bulleted lists (itemize): we just have to go to Document Settings Bullets . There we can choose the symbol for all four levels, either from the six offered “fonts” or by inserting our own Building documents 43

symbols. We can also change the size for each symbol choosing any option from “tiny” to “Huger.”2 However, setting numbered lists is not so easy. We will approach this topic in the last part of this book, in the chapter 9.

4.1.4 Math There are two “styles” for mathematical expressions: in-line and displayed, with the last one that can be “numbered” or not. The main difference between both styles is that in-line expressions pro- vide smaller symbols (integrals, sums) that look better within a paragraph. 푏 Compare how this in-line expression is presented ∫푎 푓 (푥)푑푥 with its dis- played counterpart 푏 ∫ 푓 (푥)푑푥 푎 The in-line style is available in the main toolbar, while both styles are can be inserted with the menu Insert Math . But the easiest way to insert math expressions is surely with the keyboard shortcuts Ctrl M for in-line expressions and Ctrl M for the displayed ones. It is also possible to use these shortcuts to convert one kind of expression to the other: by pressing Ctrl M inside an in-line expression, it turns into a displayed one. It is possible to create numbered expressions using the menu Insert Math Numbered Formula , or we can turn a displayed expression into a numbered one with Alt M , then N (this combination also toggles num- bering):

푏 ∫ 푓 (푥)푑푥 (4.1) 푎 Latter in this chapter we will see how to cross-reference mathematical expressions (and other items). By default, displayed expressions are centered in the text area, but since 2.3 LYX offers support for the mathindent package, with which it is possible 2. We will return to the meaning of those names in the chapter 6 where we will talk about typography. 44 Working with LYX to set the math expressions with indentation instead of centering them. To do so, it is enough to go to Document Settings Math Options to change the corresponding option. There it is also possible to select the side in which the numbering is presented. In the figure 2.1 on page 20 we have seen the equation editor at work: menus, buttons or pure code, everything is possible in it. Tons of keyboard shortcuts are predefined for the equation editor. Many of those keyboard shortcuts start with the combination Alt M : Alt M , then G , then a character gives us a Greek character, Alt M , then F for a fraction, Alt M , then ( the scalable round brackets, Alt M , then L moves the limits of an integral from the right to top-bottom part (the command \limits), etc. By moving the mouse pointer over the buttons in the tool- bars, we can see the corresponding keyboard shortcuts for those actions. The possibilities offered by LYX’s equation editor are almost unlimited and it makes no sense to repeat here what is already explained in the doc- umentation that comes with the program, so after this brief introduction, I invite you to check the manual in Help Math : do not worry about its more than 80 pages, it is an easy and quick read.

4.1.5 Tables Both, from the standard toolbar or from the menu Insert Table , we find the classic options to insert a tabular layout with the needed number of rows and columns. With the cursor inside the table, we have a toolbar that can be used to add or delete columns or rows, merge cells (multi- or multi-row), choose borders, rotate a cell or the whole table by 90º, etc. Tables can be nested: with the cursor inside a cell, it is possible to insert another table. This can be used to simulate multi-line cells: it is not possible to insert line or paragraph breaks, so we have to put in the cell another table without borders and the needed number of rows. With a right click Settings , we have many more options, such as rotat- ing the cell content at an arbitrary angle or set a “multi-page” table whose content can be split over several pages automatically. Other than manually setting the borders of our table, in the Borders tab we have two “styles:” Default and Formal. The first one presents both, Building documents 45

Figure 4.2: Setting the table width horizontal and vertical borders, while the second one only shows horizontal borders. Clearly, we can build the format we want for any table, but at the mo- ment there is no way to save a custom format for later use with other tables. For this reason, if we do not like the two available styles and do not want to redo all the formatting again each time a table is needed, the only option is to keep a separate document with “table snippets” from which we can copy & paste. Something important to remember is that, from the table settings, we can modify the width of the table: by default, the table takes the minimum width needed, but we can easily set it to take a fixed percentage of the text area, for example, as you can see in figure 4.2. In fact, fixed the width of the table we can later set the relative widths of each column. Now, how do we change the table color? We can change the text color with a right click Text style Customized 46 Working with LYX or by using a custom character style (we will return to that in chapter 8). But what about the cell background? Well, for that we need a special LATEX package (colortbl) and a bit of work: everything is explained in section 2.11 of the manual found in Help Embedded objects . But before trying to follow that path, I recommend you to carefully read the third part of this book: this topic will need a good deal of pure LATEX code.

4.1.6 “Boxes” In the menu Insert Box we have several options (frameless, simple frame, oval). The question, of course, is what those options do. Basically, by default they insert something that LATEX call minipage: a small “page” floating on top of the real page. This small page can have a bor- der or even a background color. It is important to keep in mind that these mini-pages cannot be divided into several pages, therefore, if the content does not fit on a single page, we will have problems... Their use is then the insertion of notes, for example, or of small “clarifications” that complement the main content. Now, if Insert Box only inserts a mini-page, why the menu is not called “insert minipage”? The answer is, clearly, that these “boxes” do much more, that there are more options. With a right click on the box label we get a menu that not only allows the change between the different available options, but also gives access to the box settings. In this configuration menu, it is possible to change many things, such as the box width. But most importantly, it is possible to change the “inner box,” as you can see in figure 4.3. We have three options there:

Makebox For short texts within a single line

Parbox To “frame” a particular paragraph

Minipage What was discusses above

All the options in this menu are clear, hence, I let you play a bit with them. Building documents 47

Figure 4.3: Setting a “box” 48 Working with LYX

4.1.7 Figures, tables and other “floats” In programs like Writer, when we need a figure or table with its caption, we usually insert the picture first and then add the caption. Well, in LYX we need to do exactly the opposite. Either with the corresponding button in the toolbar, or from Insert Float ... we can insert a “float” in which we can write the caption and then insert the picture or table. These floats do exactly what their name say they do: they float on top of the page. Depending on the available space, the floats will go either to the top of the page, at the bottom or they will go to the next page (only when there is no space left) allowing the text to flow comfortably around them without any additional work. The float behavior can be set either for a particular float (right click on its label) or in general for all the document from Document Settings Float Placement . Generally speaking, letting LATEX to do the job on its own (Use default placement) is a good idea: it does it really well. Now, LYX gives us the possibility to easily choose where the caption goes: top or bottom of the figure/table. We just have to move the cursor up or down the caption, as you can see in the upper part of figure 4.4. Another thing that is shown in figure 4.4 is the possibility of working with subfloats: figures (or tables) within figures, numbered like “figure 3A”, etc. It is enough to insert a float inside the main float to meet our needs. These “subfloats” can be inserted in any position: one on top of the other, from left to right... It is important to keep in mind that if we want a float without caption, it is enough to delete the corresponding box. If we later want to reintroduce it, with the cursor inside the float go to Insert Caption . We will talk more about figures and other floats in chapter 14.

4.1.8 Cross-references

LYX does not have an automated tagging mechanism. For this reason, to insert a cross-reference to a chapter, equation or figure, we need a simple two-step process. With the cursor next to the object to be referenced, we must first create Building documents 49

Figure 4.4: Workingwith floats. In the upper part of the figure we see how the float looks in the editing window, indicating where we can put the image. In the lower part of the figure we see that is also quite easy to have subfigures: we simply insert a figure float inside the main one and let LYX do its magic. As you can also see on this figure, I do not like subfigures. 50 Working with LYX a label, either with the “Insert label” button or from Insert Label . Then we can “call” the reference with the option “Insert cross-reference,” again from the toolbar or from the menu. As already commented in the general introduction, the labels can be placed in different contents: figures, tables, numbered equations, chapters, parts or sections, footnotes, whatever is needed. LYX easily understands which kind of content is being tagged and inserts the right type of cross- reference. It is important, when inserting a label, to give it a name that we can later recognize. It is a good idea to accept the suggested pattern that LYX offers by default, prefixing the label with a few characters that help to understand if we are talking about a chapter, figure, or anything else. Now, let’s assume that we want to change the title of a chapter, or that we “promoted” a subsection by converting it into a section, is it possible to change the label name? Of course! But without ruining cross-references to it? Without a shadow of a doubt! With a right click in the label, we can change its name without worries: all cross-references will be updated automatically. Speaking of cross-references, the menu you get when you insert them is very clear, so I will just point out its most interesting features: • In the upper part of the window we can choose between the open documents, something that makes the insertion of cross-references between documents incredible simple • There is a “filter” to facilitate the search for the label we need • In the lower part of the window there are different options for the cross-references: number or text, page, both... In figure 4.5 we can see both menus, the one used to create the label and the other to introduce a cross-reference to that label.

4.1.9 Indexes Changing the default settings of an index, either a table of contents (TOC), word index, any kind of index, is one of the most difficult tasks in LATEX. There are several ways to set up indexes: in fact, there are several ways to create an index. Building documents 51

Figure 4.5: Creating a label (above) and inserting a cross-reference (below). And yes, the names of the label are in Spanish, sowhat? 52 Working with LYX

Fortunately, in the bast majority of cases, the default index is perfect, so we just have to go to Insert List/TOC ... to create our index of contents, figures, tables... Because it is one of the advanced LATEX topics, we will leave the change of the index settings for the final part of this book, in chapter 10.

4.1.10 Generate a “dynamic” PDF: the Hyperref package

The hyperref package can be used to set up the PDF output of LATEX docu- ments so they have “active links,” either within the document, to web-sites or to external files. In LYX we can set up several options of Hyperref package by simply selecting some check-boxes, while other options (such as choosing colors for the different kinds of links) can be configured by writing some parameters in a text line. Opening Document Settings PDF Properties we get what is shown in figure 4.6. As you can see, in the General tab it is possible not only enable support for the Hyperref package in the document, but we can also establish the general properties of the PDF file, such as its name, author, if it should open full-screen, etc. In Hyperlinks tab, we find more options for Hyperref, such as giving color to the links... but we do not have a graphical tool to set those colors. In the box called Additional Options is where we have to write, sepa- rated by commas, those options of the Hyperref package that cannot be set graphically. For example, after enabling “Color links” it is possible to determine the color for each type of links using the following instructions: citecolor sets the color for bibliography links filecolor sets the color for links to files linkcolor sets the color for “internal” links (cross-references, index) urlcolor sets the color for web links Building documents 53

Figure 4.6: Setting the Hyperref package 54 Working with LYX

Colors can be called by name (red, green, cyan, magenta, black) or by RGB values, with three numbers between zero and one. I generally use the option “no frames around links” because I hate having links inside boxes, but if someone prefer to use those “boxes,” their color can be set with in- structions such as linkbordercolor and similar. The Hyperref package documentation is usually installed in /usr/share/texmf/doc/latex/hyperref/manual.pdf Writing something like

citecolor=cyan,filecolor=green,linkcolor=red, urlcolor=blue we will obtain a PDF not only “linked,” but also “colorful.” Something important in the Hyperlink tab is the option “Break links over lines,” because not using it means that a link will not break at the end of the line, going without shame through the right margin. In the “Bookmarks” tab we should never forget two really important options, necessary to obtain properly numbered : “Generate book- marks (TOC)” and “Numbered bookmarks.” As last comment, remember that LYX has a graphical tool to insert ex- ternal links (see figure 4.7).

4.1.11 Navigate and organize the document From the Navigate ... menu we can access the entire document: from there it is possible to go to any chapter, figure, table, footnote, equation... The menu Navigate Other lists Labels and references is something you should not overlook. There we see not only the list of all labels used in the document: we also have the list of references to those labels, so we can quickly see from where we are calling them. But there is another way to browse the document, a method that allows us to also organize it: View Outline Pane , as you can see in figure 4.8. As the screenshot shows, at the top of the tool we can choose what kind of information we want to navigate or modify (table of contents, equations, figures, etc.). Below that drop-down menu there is a “filter” field for the “tree view” list that follows. This filter is very helpful when searching for a particular heading or element. Building documents 55

Figure 4.7: Creating a link in a document

Figure 4.8: The Outline Pane during the edition of this book. The “Keep” checkbox is really useful when it is necessary to go back and forth through the document, while the buttons in the lower right corner can be used to quickly change both, the order and the hierarchy of chapters, sections and other elements in our book. 56 Appendixes

It is important to note that when you click on an item in this list, the edit point moves to that item, but the click also closes that branch in the hier- archy. Toavoid that we have the “Keep” button, which makes the branches only open/close by clicking on the arrows to the left of the corresponding entry. The slide bar can be used to globally select up to which level the tree view remains “open.” Finally, the buttons in the lower right corner (they are available only for the table of contents) give us the possibility to change the title level or to move a particular chapter/section above or below of another of the same level, allowing us to quickly change the order of the headings.

4.2 Appendixes

With Document Start Appendix Here we can start a new “part” in the doc- ument, indicated in the LYX editing window with a red box that says “ap- pendix” at the top, and that is the place of the document where we can write, you guessed it, the appendixes. To insert an appendix or sub-appendix, we just need to use the Chapter and Section environments, respectively. Cross-references to appendixes and everything related to them work without problems in the usual way. It is important to keep in mind that, by default (or by definition?), the appendixes go to the end of the document. It is possible to create appendixes “by chapter” or “by part,” but until now I did not find a good enough reason to do so, so I never worried about that possibility.

4.3 Bibliography

In a LYX document there are two ways of working with bibliographic ref- erences: internal to the document or through the use of an external biblio- graphic database such as BibLATEX. Starting with version 2.3, LYX offers support for BibLATEX, but entering such a big topic really goes beyond the general scope of this book, so I will only provide a quick overview to the “internal” method. Building documents 57

Everything starts with the “bibliography” environment. After inserting it, we get a new “section” called References and the first empty entry with a gray label called “key-1[].” With a click on that label we can change the key to something more descriptive or provide a label that could be used to show the citation in the document: if the key is left blank, the citation will be numbered. It is important to keep in mind that this dialog does not accept spaces nor non ASCII characters. After the label, we can write the citation text, formatting it “by hand” (italic for the title, bold for the page number, etc.). Finally, we can go to Insert Citation to select the citation(s) needed, their format, add text (such as “[5, chapter 6]”), etc. Two important observations:

• Being an environment, it is always possible to “quit” it to add another environment, such as a chapter or section after it. This means that we can group our citations by chapter, for example.

• The list of citations remains in the exact order in which it was issued, so it is important to keep track of their order in the document. Re- member: it is quite easy to move paragraphs up or down with a sim- ple right click.

4.4 Language

In Document Settings Language we have a few options, but they are all important. In this section we will discuss all of them.

4.4.1 New in 2.3: “dynamic and ‘nested’ quotation marks” Many languages, such as English, can use nested quotation marks like the ones you see on this subsection heading. Other languages use different com- 3 binations and from LYX 2.3 it is possible to set-up the combination we need.

3. https://en.wikipedia.org/wiki/Quotation_mark 58 Language

The external marks are inserted as usual (in my Spanish keyboard, it is 2 ), while in order to insert the inner marks we only need to add Alt to the combo. By selecting “use dynamic quotation marks,” the quota- tions marks automatically adapt if we later change their style: without that options, they remain fixed. When dynamic quotations are used, we can even change the type of quotation marks in a case by case basis with a right click on the mark.

4.4.2 Dictionaries For all of us, Linux users, spellcheck dictionaries are already installed with the system (LibreOffice brought them for sure), but maybe we could miss the thesaurus. Or perhaps we need to use different or more updated dictio- naries. It is even possible that someone is even using a different operative system. In this subsection we will see how to use different dictionaries in LYX. First of all, we have to download the dictionaries, for example, from LibreOffice’s extension repository,4. Now, if we change the name of the downloaded file from .oxt to .zip and unpack it, we can see several files and probably some folders. Everything we need are the files with the following extensions:

• .dic and .aff: these are the spell-check dictionaries

• .dat and .idx: these are the thesaurus files

Moving those files to an appropriate folder, now we need to open in LYX the menu Tools Preferences Paths as you can see in figure 4.9. Now LYX will use the dictionaries that we place in the selected folder (in the screen-shot, only the thesaurus folder was changed, but selecting a different directory for hunspell dictionaries works in the same way). In the menu Preferences Language Settings it is possible to activate the “real time” spell-checker, while the keyboard shortcut F7 opens the thesaurus for the word at the cursor position. It is important to keep in mind that if we have the .aff files in our folder, the thesaurus recognizes

4. https://extensions.libreoffice.org/extensions?getCategories=Dictionary Building documents 59

Figure 4.9: Changing the paths to the dictionaries 60 Language

“modified” words (plurals, conjugated verbs, etc.), although it only suggests “unmodified” words (singular forms, infinitives, etc.).

4.4.3 Babel vs. Poliglosia Language definition affects much more than spell-checking: from simple things like translating “Chapter” into “Capítulo” for a document in Span- ish, up to the difficult decision of getting rid of the first line indent after a heading (no, it is not only Americans: Spaniards also keep that first line indent) the language settings are responsible for many things in our docu- ments. Historically, LATEX has always relied on an external program called Babel to take those decisions. The problem was that, also historically, Babel used to have some difficulties with languages that use different writing systems. This situation worsened when Unicode arrived, so an alternative project, called Poligosia, was started. In fact, LYX uses Poliglosia by default in docu- ments that use system fonts. Now, not only the latest versions of Babel solved most of those prob- lems: for languages such as English, Spanish or any other that use the “Latin” script those problems never existed. That is why, in the rest of this book, I will only talk about Babel.

4.4.4 Babel options in LATEX/LYX Not of real use for English speakers, but for some languages Babel offers several options that can be set-up through parameters. In Document Settings Language , it is possible to select Custom as lan- guage package and, in the box, write an instruction such as:

\usepackage[language,option1,option2]{babel} where option1, option2… are the options we want. For example, to set a document in Spanish in which the first line indent is dropped after a heading and where Roman numeral are written in small caps, we need to write

\usepackage[spanish,es-noindentfirst, es-ucroman]{babel} Building documents 61

4.5 Import and export documents

One of the most enduring myths in modern times is that of the “interop- erativity:” the idea that you can work without trouble in different systems and different programs, but in a single document. I will not enter into the discussion of why this interoperativity is almost impossible outside the web (it would take me too far from the content of this book), but the sad truth is that if we work on a text document with any software and then move to another software we will always get in trouble. That, of course, does not mean it is impossible. From 2.2, LYX offers integration with Pandoc, a program that allows us to convert between different document formats. With Pandoc and other filters already present, it is possible to import and export to and from LYX, documents formatted as odt, doc, docx, ... Everything is under File Import / Export . Just do not expect miracles: if the document that we are migrating is complex, it will need attention. Clearly, import and export of LATEX documents works perfectly. In fact, if we copy a fragment of a LATEX document to the clipboard, we have the option of a “special paste” that converts everything to LYX format without effort.

4.6 Copy information from other programs

Copy&Paste between programs has always been, is, and will be, problem- atic, and LYX is no exception to this rule. But “difficult” does not means “impossible,” so here you have some tips and tricks to simplify the painful task. Pasting with Ctrl V in LYX only gives “Plain Text, Join Lines” and that means losing all formatting and paragraph or line breaks. With Ctrl V we get “Plain Text,” with paragraph breaks. In Edit Paste Special there are a couple of more options, but beyond “Paste from LATEX” (if we copied from LATEX, of course) there is nothing to get excited about. In fact, copying pictures or object is almost impossible. 62 Change tracking

Something that can be copied (almost) without problems are tables, ei- ther from HTML documents in our internet browser (easy), LibreOffice Calc or Calligra Sheets spreadsheets (equally easy) or even tables in word processors such as Writer (with some extra work). Let’s say that in an HTML document or in a spreadsheet we have a table of, say, 6 rows by 4 columns. After copying, we go to LYX and create a table with the same dimensions. Finally, with the cursor in the first cell (top left): Ctrl V . And that’s it. Formatting get lost, but the content will be there. Copying from Writer is more work. As before, we need to create a LYX table with the right number of rows and columns, but first of all we need to go to Writer, select the whole table and Table Convert Table to text , selecting “tabs” as separator. Now it is enough to copy the resulting text, to go to the first cell in the LYX table and Ctrl V .

4.7 Change tracking

LYX provides a change tracking system to record the different stages of a document development and that can be useful when many people work in the same file. It all starts at Document Change Tracking Track changes , or with the keyboard shortcut Ctrl E . Changes will be indicated depending on their type: underlined text for new entries, crossed out for deleted text, etc. When change tracking is active, we can see a new toolbar with buttons to accept or reject changes, browse them and everything needed. The system is quite easy to use and it is perfectly documented in the section 6.16 of the user guide you find in Help User’s Guide . Also, I must admit that it is not something I use a lot. Wecould say that as a writer I am a “lone wolf”... and disorganized.

4.8 Working with “branches”

Suppose we want to create a document with “variants” that can be quickly selected both to hide them or to show them in the final version. The sim- plest example is a test with several questions and their corresponding an- Building documents 63

Figure 4.10: Our first branch. Wewill discuss the green color later.

swers: we want the students to only see the questions, but also to give the teachers who must correct the exam the complete document with every- thing and answers. Or maybe we have to write a manual for a product that has three simi- lar but not identical models, so selecting one variant or the other when we create the PDF we can obtain different manuals from the same document. LYX offers a powerful tool for this task: branches. In any document, it is possible to create a branch with Insert Branch Insert New Branch . We will see an exclamation mark (No Branches Set for the Document!) and the mentioned option to create the first branch. Some branch must be the first. If we call our first branch “Questions,” after accepting we find some- thing similar to what we see in figure 4.10. Do you notice the “X” to the left of the label? We will come back to that. In the red box we can now insert any kind of content: text, headings, figures, tables, equations... If we now go back to Insert Branch Insert New Branch we can see that, in addition to the creation of a new branch, the exclamation point was re- placed by the branch we just created. And that is how everything works: we can have several separated blocks in the document, all grouped under the same “branch,” so all those blocks are displayed or hidden simultaneously. Also, we can have several branches that can be shown or hidden independently. By default, all branches are disabled, therefore, if we compile the docu- ment they will not be displayed.5 This status is shown by the “X” to the left

5. In fact, if all we have in the document is a hidden branch, the document will not compile. 64 Working with “branches”

Figure 4.11: Activating a branch of the label we mentioned earlier. To activate or deactivate a branch, it is enough a right click on any label of the branch, as you can see in figure 4.11. Now the “Questions” branch shows a “check-mark” on the left, indi- cating that the branch is enabled and will be shown in the final document. The menu have four more options:

Invert inset this is a new feature in LYX 2.3: the possibility of “inverting” an inset belonging to a branch, so it is shown when the branch is hidden.

Close inset this option hides the content of that block, only the label will be visible

Dissolve inset the content of the box will be moved to the main docu- ment, cutting it from the branch

Settings this menu can be used to “migrate” that block to another branch.

Another way to control branches, not only to activate/deactivate them, but also to merge them, change their name, set a color (only seen during editing)... is going to Document Settings Branches . And in this way, with a couple of clicks, we can change from the situ- ation shown at the top of figure 4.12 (to the left the LYX document, to the right the compiled PDF) to what is seen at the bottom of the figure. Cool, isn’t it? Building documents 65

Figure 4.12: Two branches in action, with only one (top) or both active (bot- tom). In both cases, we have theY L X editing window to the left and a frag- ment of the PDF to the right.

4.9 Master documents

In LYX it is incredible simple to split a document into “subdocuments” and to combine them into a “master document.” Working on each document, making cross-references between them... everything is an easy walk. First of all we need to make clear that, unlike other applications such as Writer, there is no real difference between a “master document” and a “child document.” In fact, it is possible to have several levels of documents, with a first one being “the master,” a second one being “the first child,” and a third one being “the first grandchild.” What is important is that the prevailing documentclass will be that of the highest level, so if a subdocument have a particular feature (a module, for example) we need to be sure that that feature is also available in the main document. OK, let start to work. In the main document, with the cursor in the point where we want to insert the “child” document, we need to go to Insert File Child Document to obtain what is partially shown in figure 4.13 on the next page. This menu offers several options for inserting a child document. With the first one, Include, the document is presented in the editing window as a button centered on its own line: with a click on this button, we can ac- 66 Master documents

Figure 4.13: Insert a “child document” cess the child document properties, where we have a button to open the document to edit it. When the master document is compiled, the child doc- ument inserted in this way starts on its own page and will show a page break after it. If we use Input instead, the document goes to the same page in which it was inserted, starting on its own line. The two last options, Verbatim and Program Listing, introduce the code of the child document. I let you exploring the use of these options. If we have all documents and subdocuments open simultaneously, each in its own tab, the numbering of sections and chapters in the editing win- dow follows the actual order used in the complete document, giving a clear idea of the structure of the finished document. Making a cross-reference between different documents and subdocu- ments is incredible easy if we have all those documents open simultaneously: every label will be available from every document. And that’s it. No, seriously, that’s it: working with master and child (and grandchild) documents in LYX is as easy as working on a single docu- ment with everything included. Super cool. There is more information in the section 3.2 of the manual you can find in Help Additional Features . Also here: https://wiki.lyx.org/FAQ/Multidoc Part III

Beyond the basic settings Where the full power of LATEX, X TE EX, OpenType and LYX is unleashed

It’s full of stars! Chapter 5 Some commands

LYX cannot provide support for each and every aspect of LATEX from its in- terface, and that means that if we want to cross certain formatting frontiers we will have to start writing LATEX code, either in the preamble or directly in the document. This sound more difficult than it really is, so do not panic just because we have to write some lines of weird looking code... but of course do not relax too much either, because doing things without understanding how they work is an invitation to disaster. For this reason, I invite you to go through the final pages of this book with a calm pace, that the remaining path is interesting and the tools we will find in it are full of possibilities. In this chapter we will see how to insert code in our documents, as well as a quick review of several instructions we will need to use many, many times. Let’s start with it.

5.1 TheAT L EX preamble

We have already talked about the importance of the LATEX preamble in the introduction of this book: it is the place that allows us to define things that can be used throughout the document. It is accessible from Document Settings LaTeX Preamble , and there we

69 70 The TEX box can write all the code we will see in the following chapters. An instruction we will see many times is the one that activates a partic- ular package from our LATEX distribution. For example, to write the XƎTEX “logo” I used the package hologo, writing in the preamble

\usepackage{hologo}

As you can see, an instruction with a clear name (\usepackage) is used to tell the system to use a particular package (hologo). Some packages offer the possibility to adjust “parameters” that change the package behavior. This can be done directly when calling the package or by using specific instructions, available only when the package has been activated, while other packages will offer, or even demand, both possibili- ties. In some cases, we will have to “patch” a package to change it with the \renewcommand command, and we will even use some logical statements to determine when (or if) a change should be used. Many options we will see in the following pages. Unfortunately, not all instructions are so clear: \makeatletter, for example, can easily create confusion in someone who is new to all this. Simplifying a bit (or a lot), the character @ (at) is special in LATEX... ex- cept when it is not. When we redefine a command that uses @ in its name, \makeatletter (make @ a letter) transforms @ into a “normal” character, while \makeatother (make @ other) turn it back to “what LATEX says it is.” Therefore, there is no need to worry too much about that thing: we are not going to delve so deep into these topics, but as you can see, we are now entering a complex world in which a steady pace is needed.

5.2 TheE T X box Either with the corresponding button in the main toolbar or simply with the keyboard shortcut Ctrl L we get a red box waiting for code. Tocontinue with the hologo example, to build the XƎTEX logo we have to write inside one of those boxes the command

\hologo{XeTeX} Some commands 71

In the LYX window this is shown as: \hologo{XeTeX}

Note: In this book I used a character style instead. We will come back to this in the chapter 8 and in the appendix B.

This boxes can accept several lines of code and any instruction we need, they are not limited to “short” expressions.

5.3 A matter of “size”

There are LATEX instructions to define the text size. These instructions can be seen, ordered from the smallest to the largest, in the table 5.1 which lists the size values for different document classes and some base sizes.1. As you can see, all these sizes are fixed, proportional to the base size de- fined for the document. And that means that while we have a great variety that covers almost any imaginable situation, we do not have absolute free- dom. To obtain arbitrary font sizes there is a really easy to use command \fontsize{font-size}{line-heigh}.

{\fontsize{5cm}{5.5cm} A really big text!}

gives us a 5 cm font with a 5.5 cm line space. To know more: https://en.wikibooks.org/wiki/LaTeX/Fonts#Sizing_text

5.4 A matter of “shape” (typographical)

We will talk a lot about typography in the next chapter, but sometimes it is not necessary to go into so many details. Many times it is enough to indicate the variant of a font. This will be really useful in chapter 11.

1. A technical detail: LATEX uses a definition of “point” (theE “T X point”) different from the standard one (or “PostScript point”). The difference is really small, below the 0,4%, but exists: https://en.wikipedia.org/wiki/Point_(typography)#American_points 72 A matter of “shape” (typographical)

Standard classes, AMS classes, memoir Size [10pt] [11pt] [12pt] [10pt] [11pt] [12pt] \tiny 5 6 6 6 7 8 \scriptsize 7 8 8 7 8 9 \footnotesize 8 9 10 8 9 10 \small 9 10 10.95 9 10 10.95 \normalsize 10 10.95 12 10 10.95 12 \large 12 12 14.4 10.95 12 14.4 \Large 14.4 14.4 17.28 12 14.4 17.28 \LARGE 17.28 17.28 20.74 14.4 17.28 20.74 \huge 20.74 20.74 24.88 17.28 20.74 24.88 \Huge 24.88 24.88 24.88 20.74 24.88 24.88

Table 5.1: Size value represented by the different instruc- tions according to the size of the base text. In the table, the document classes to create slides have been ignores. Source: https://en.wikibooks.org/wiki/LaTeX/Fonts#Sizing_text

As we have already seen, in a LATEX document we have three “font fam- ilies:” serif or “roman,” sans serif and “typewriter” or monospaced. Each of these families can have a “weight” that is indicated by a “series” (bold, semibold, light) or a “shape” (normal, italic, slanted, small caps, etc.). Each of these families and each of these shapes can be called with a spe- cific LATEX instruction. Then we have three types of instructions,

\XYfamily \XYseries \XYshape where XY are two characters that represents the feature we are looking for. The families are represented by

• rm for Roman: \rmfamily

• sf for sans serif: \sffamily

• tt for typewriter: \ttfamily Some commands 73

The “series” are represented by

• bf for bold: \bfseries

• md for “medium”: \mdseries

• lf for “light”: \lfseries

And last, the “shapes” are represented by

• it for Italic: \itshape

• sl for slanted: \slshape

• sc for Small Caps: \scshape

• etc.

For a complete list of these commands: https://en.wikibooks.org/wiki/LaTeX/Fonts#Font_styles

5.5 Numbers!

Undoubtedly, we will need to number things with “normal” numbers, Ro- man numerals or even letters. Each kind of numbering has an associated instruction:

• arabic for Arabic numerals: 1, 2, 3, 4...

• Roman for uppercase Roman numerals: I, II, III, IV...

• roman for lowercase Roman numerals: i, ii, iii, iv... (poor Romans!)

• alph for lowercase letters: a, b, c, d...

• Alph for uppercase letters: A, B, C, D...

We will see examples of these instructions in use, don’t worry. 74 Reconfigure!

5.6 Reconfigure!

In the following chapters, we will find several LATEX packages we need to use to complete all the “tricks.” Many of these packages are installed by default in modern LATEX distributions, but not all. Now, it is not enough to install a package in order to use it: we have to tell LYX that a new package has been installed! For this, after changing anything in our LATEX installation, we must go to Tools Reconfigure , wait a few seconds for LYX to verify everything and restart the program when requested. Chapter 6 LYX, OpenType and typography

Before starting, an important note: in this chapter and those that follows we will make extensive use of the “TEX boxes” and the LATEX preamble, because there is no alternative to the use of code. But don’t worry, it is not that difficult. In fact, later in this book (chapter 8) we will see how to simplify everything even more with the creation of styles. OK, back to the main topic of this chapter: we have defined an Open- Type font for our document, but we want to go beyond the default options and activate some “additional features.” This can be done in different levels:

1. Few and small pieces of text

2. Many and perhaps not so small pieces of text

3. The entire document

4. Mathematical formulas

In this chapter I will talk about these possibilities, but also about some more general topics: line spacing, hyphenation, and . To use OpenType we need to know how to call its substitution tables. In what follows in this chapter and this book I will take as reference the page of Dario Taraborelli: http://nitens.org/taraborelli/TeXOpenType and the wikipedia page

75 76 OpenType for the predefined font

https://en.wikipedia.org/wiki/List_of_typographic_features As an example, in the table 6.1 you can see some of the more used tags. It is important to keep in mind that not all fonts offer all these options. Also, some of these options are enabled by default (such as typographic ligatures) while others must be activated by hand.

6.1 OpenType for the predefined font

Suppose we want to enable a special OpenType option at a particular point of the document. For example, to impress our readers, we could use a short text with historical typographical ligatures, or perhaps write a fraction such as 123⁄37 without using the equation editor. As already said, later in the book we will see how to define a character style to simplify the use of these instructions, but first we have to learn some things, so let’s be tough and write some ugly code, yeah! Weneed to combine the instruction addfontfeature with the “Open- Typename” of the feature we want to activate. For this task, we can use two “TEX boxes” that surround the text to be modified. For example, for histor- ical ligatures we can either use {\addfontfeature{RawFeature={+hlig}} historical } (the plus sign “+” activates the option “hlig”) or {\addfontfeature{Ligatures=Historic} historical } to obtain, in both cases, the same result: historical. The brace that opens the first “TEX box” and the lone one on the sec- ond are both important: they tell the system to limit the application of this feature to just that region and not to everything that follows. Clearly, it is possible to activate several options at the same time: we just have to separate them by commas. For example

\addfontfeature{RawFeature={+hlig,+onum}} activates the historical ligatures and the old style numerals simultaneously. It is important to note that these instructions can also be used to disable default features. Everything is on Dario Taraborelli’spage linked above, but, for example, if we want to disable the contextual ligatures, we can use either LYX, OpenType and typography 77

Feature Label Name in Fontspec Numbers Lining lnum Numbers={Lining} Old style onum Numbers={Oldstyle} Proportional pnum Numbers={Proportional} Tabular tnum Numbers={Monospaced} Slashed zero zero Numbers={SlashedZero} Ligatures Standard liga Ligatures=Common Contextual clig Ligatures=Contextual Discretional dlig Ligatures=Rare Historical hlig Ligatures=Historical Forms, styles, position and variants Small caps smcp Letters=SmallCaps VerticalPosition= Superindex sups Superior VerticalPosition= Subindex subs Inferior VerticalPosition= Scientific inferiors sinf ScientificInferior VerticalPosition= Ordinals ordn Ordinal Stylistics sets ss01...ss20 StylisticSet=1 ... 20 Stylistics alternates salt Style=Alternate swsh Style=Swash Fractions VerticalPosition= Numerator numr Numerator VerticalPosition= Denominator dnom Denominator Fractions frac Fractions=On Alternate fractions afrc Fractions=Alternate

Table 6.1: Some OpenType tags and their use 78 Defining a font family

\addfontfeature{Ligatures=NoContextual} or

\addfontfeature{RawFeature={-clig}}

(the minus sign “-” disable the option “clig”).

6.2 Defining a font family

What is shown in the previous section is (relatively) OK only if we have to use it a couple of times: writing all that code many times would be a real nightmare. For this reason, and others that we will see later, it is a good idea to define a “font family” with the desired features on. Also, we will not be limited by the predefined font. Let’s suppose we want to define a new font to be used in our docu- ment, for example EB with historical ligatures. In the menu Document Settings LaTeX Preamble we need to write:

\newfontfamily{\storiclig}[RawFeature={+hlig}] {EB Garamond}

Using this new font family is similar to what we did in the previous section (obviously, writing less): two “TEX boxes” surrounding the text to be mod- ified: {\storiclig{ historical }} Notice the double braces at the end. So, yeah, it is easier than before... but far from ideal. Don’t worry! We will come back to this in the chapter 8 where everything will become almost idyllic.

6.3 OpenType for the entire document

Let’s suppose that we want our document to use the EB Garamond font, but we do not like the “old style numerals” it uses by default, we want to LYX, OpenType and typography 79

use lining numerals instead. For the sake of a complete example, let’sassume that we also want to activate the “swashes” that this font offers for some italic upper-case letters. As previously mentioned, in a XƎTEX document we have three main font families: “Roman,” “Sans Serif” and “Typewriter.” Let’s focus on the first two. If we use the menus to select fonts, LYX “hides” these instructions, but to set the main font of the document the in- struction \setmainfont is needed while to set the Sans Serif \setsansfont is used. The reason for providing these instructions here is that, because LYX hides them, we do not have the opportunity to configure them as we need, therefore, we need to use these instructions explicitly in the preamble. In LYX, under Document Settings Fonts we we have to select “Use non-TeX fonts (via XeTeX/LuaTeX),” but leave the selection box for the font in Default: we will set that manually in the preamble. Just to be sure, in that same menu, under ... Formats , select PDF(XeTeX) for “Default output format.” Finally, in the “LATEX Preamble” we need to write:

\setmainfont{EB Garamond}[ RawFeature={+lnum}, RawFeature={+swsh} ]

For different font features, we just need to change the tags. For more font features, just add a comma and a new line for each one. And, of course, for a different font, just change the name. The \setsansfont instruction works the same way.

6.4 Different fonts for different “shapes”

Let’sgo directly to an example: the Plus font is quite “feature rich,” but only offers “normal” and “italic” shapes, not bold nor bold-italic. The Gentium Basic provides all four basic shapes, but has fewer options and a shorter Unicode coverage. Both fonts have the same general design, how can we tell XƎTEX to automatically use Gentium Plus for normal and italic text while using Gentium Basic for bold and bold italic? 80 Different OpenType options for each “shape”

\setmainfont[BoldFont = Gentium Basic Bold, ItalicFont = Gentium Plus Italic, BoldItalicFont = Gentium Basic Bold Italic, ]{Gentium Plus}

6.5 Different OpenType options for each “shape”

Suppose we want some OpenType features for the Roman face, others for italics, others for bold... To achieve that we need to add some code to what was presented in the previous section. To make things clear, I present here a completely arbitrary, unrealistic and absurd example: for the Vollkorn typeface I will activate the first stylistic set for the Roman face, the 17th stylistic set for italic, the 14th for bold and the slashed zero for bold italic:

\setmainfont{Vollkorn}[ UprightFeatures={ RawFeature=+ss01, }, ItalicFeatures={ RawFeature=+ss17, }, BoldFeatures={ RawFeature=+ss14, }, BoldItalicFeatures={ RawFeature=+zero, }, ]

Pay attention to the commas! To get more options for each face, simply add them separated by com- mas:

ItalicFeatures={ LYX, OpenType and typography 81

RawFeature=+hlig, RawFeature=+swsh, Numbers=OldStyle, },

We could even choose a different color for each shape... but I let you explore chapter 6 of the fontspec documentation, which is usually installed in /usr/share/texmf/doc/latex/fontspec/fontspec.pdf

6.6 Apply a stylistic set to a particular character

And just in case everything we mentioned before is not enough to show you the power of XƎTEX, I will present an example applying a stylistic set each time a particular character appears. Let’s define the situation. The Vollkorn typeface mentioned in the pre- vious section offers a variant of the Q with a “long tail:” Qué Más Ninguno (Normal) Qué Más Ninguno (+ss01) The “problem,” as you can see, is that this option also changes other characters: the “a,” the “g,” “M,” and “N.” So the question we should all ask here is: is it possible to apply the first stylistic set just to Q? Of course it is possible! The inspiration for this code comes from the following article where a stylistic set is applied to all uppercase letters: http://tex.stackexchange.com/questions/33855/ can-one-set-a-specific-font-variant-in-xelatex-for-uppercase-letters- only In the LATEX preamble we need to write:

\newfontfamily{\upfont}[RawFeature={+ss01}]{Vollkorn} \XeTeXinterchartokenstate=1 \newXeTeXintercharclass \uppercaseclass \makeatletter \@tempcnta=`\Q \XeTeXcharclass \@tempcnta \uppercaseclass 82 OpenType for math, 1: unicode-math

\makeatother \XeTeXinterchartoks 0 \uppercaseclass = {\begingroup\upfont} \XeTeXinterchartoks \uppercaseclass 0 = {\endgroup} \XeTeXinterchartoks 255 \uppercaseclass = {\begingroup\upfont} \XeTeXinterchartoks \uppercaseclass 255 = {\endgroup}

Done!

6.7 OpenType for math, 1: unicode-math

To finish the migration of our font to OpenType, of course we also need to change the fonts used on our math. This is easy to do thanks to the unicode-math package and several projects that offer fonts specially de- signed for this purpose, such as • the STIX project:

∘ http://stixfonts.org/

• the Garamon-Math project:

∘ https://github.com/YuanshengZhao/Garamond-Math

• Libertinus Math:

∘ https://github.com/khaledhosny/libertinus

• TeX Gyre Pagella and Termes:

∘ http://www.gust.org.pl/projects/e-foundry/tex-gyre

• Latin Modern Math:

∘ http://www.gust.org.pl/projects/e-foundry/latin-modern

• Asana Math: LYX, OpenType and typography 83

∘ http://www.ctan.org/tex-archive/fonts/Asana-Math/

• DejaVu Math TeX Gyre:

∘ https://dejavu-fonts.github.io/

• FiraMath:

∘ https://github.com/Stone-Zeng/FiraMath

• … and not many more, but with these we have more than enough.

To use all this in LYX we need to follow two small steps, one graphi- cal and the other “through code.” First of all we need to go to Document Settings Fonts Math where we need to check the cryptic option “Non- TeXFonts Default.” Now, in Document Settings LaTeX Preamble we need to write, to use the STIX Two fonts:

\setmathfont{STIX Two Math}

For Libertinus Math

\setmathfont{Libertinus Math}

Or for DejaVu (maybe someone like it…)

\setmathfont{DejaVu Math TeX Gyre}

For those fonts offering “stylistics sets” or other features, we can activate the corresponding OpenType option when we call the font. For example, to use the alternate and get more “vertical” integrals with STIX Two Math (stylistic sets 2 and 8, respectively, see the documentation accompany- ing the font) we have to write

\setmathfont{STIX Two Math}[RawFeature={+ss02;+ss08}]

We can also pick different fonts for different “ranges.” For example, we could use Latin Modern Math for “calligraphic” characters, even if the main mathematical font is different. We just need to write 84 OpenType for math, 2: mathspec

\setmathfont[range={\mathcal, \mathbfcal}]{Latin Modern Math}

One point about this: there could problems with character spacing. To resolve these problems we can add a second line with an “empty range” for the base math font:

\setmathfont[range={}]{STIX Two Math}

That’s it, even our equations now use OpenType! In Linux and with TEXLive, the documentation for unicode-math is installed in /usr/share/texmf/doc/latex/unicode-math/unicode-math.pdf There is another way to select a different OpenType font to use in our math. We will talk about that in the following section.

6.8 OpenType for math, 2: mathspec

The Unicode-math package presented in the previous section has a small limitation: the number of available math fonts that can be used. However, there is a way to use any system font to write our math: the mathspec package. With this package the symbols (integrals, brackets, a ±) come from the standard LATEX fonts, but the variables, the function names and the Greek characters come from an arbitrary font that we choose. The use of mathspec in LYX involves some extra work, but knowing the secret it is not a real problem. Let’s see how to use this great tool. First of all, it is important to keep in mind that mathspec package calls fontspec, which is used to set-up fonts in XƎTEX. That means that if we use the option offered by LYX to “use non-TEX fonts” (option that config- ures the fontspec package) together with mathspec, well, we will have a long list or errors when compiling the document, because we would be call- ing fontspec twice. Solution? Do not use the options offered byY L X to choose fonts and select them “by hand” in the preamble. In Document Settings Fonts we leave UNCHECKED the option to use non-TEX fonts, making sure that all options are in Default. Then, in LYX, OpenType and typography 85

... Formats Default Output Format we select PDF (XeTeX) (with Lua- TeX it should work as well). Now, to the LATEX preamble. For this example I will use the Cochineal font1, but it could be any other:

\usepackage{mathspec} \setmathfont(Digits,Latin)[]{Cochineal} \setmathfont(Greek)[Uppercase=Plain, Lowercase=Regular]{Cochineal}

\setmainfont[Mapping=tex-text]{Cochineal} \setsansfont[Mapping=tex-text] {Libertine Sans} \setmonofont{DejaVu Sans Mono}

The first line tells the system to use mathspec. The second and third line configure the font used in the mathematical expressions: in the second one we simply select Cochineal for numbers and text (variables, function names, constants, etc.), while in the third line we not only say from where to pick Greek characters, we also passed some “options” such as making the lowercase Greek letters upright instead of italic (the Lowercase=Regular option... it is not that I like it, but you know, for the example). The last three lines define the main font, the Sans and monospaced fonts, as we have seen before. Of course you can pick any other font or combination of fonts, that this example is rather eclectic2 In Linux with TEXLive, the mathspec documentation is installed in /usr/share/texmf/doc/xelatex/mathspec/mathspec.pdf The inspiration for this section: http://tex.stackexchange.com/questions/29100/ using-old-style-numerals-in-xelatex-in-math-mode

1. http://www.ctan.org/pkg/cochineal 2. At this point, some readers might begin to wonder if I choose my examples in a way that cannot be “copy&pasted” without some tweaking, that all my examples must be carefully edited and customized to make them work in real situations. They might be wondering that. 86 Line spacing

Figure 6.1: Selecting the line spacing in a particular paragraph

6.9 Line spacing

Here is a dilemma: for the document as a whole, as well as for a particular paragraph, LYX offers several line spacing options. The main three ones (Single, OneHalf in the document settings or “1.5” in the paragraph settings —this double naming is crucial— and Double) seem to be clear enough, but only to the point in where we realize that we have no idea what “Single” actually means. The topic is not trivial and it causes many headaches to most LATEX users. Let’s perform some tests to understand how all this works. If in a para- graph we make a right click Paragraph Settings we get the menu shown in figure 6.1. Try this. Create a text with a line spacing of “1.5” and another with a custom spacing of 1.5. Do you see the same? Do not? Custom at 1.5 gives a bigger line spacing than “1.5”! Now, come back to the “custom” paragraph and write 1.25 instead: you can see how the setting change by itself to “1.5” when you press “Apply.” Last test: write 1.667 as custom line spacing, to see how it turns by itself into “double.” What is that? LYX, OpenType and typography 87

Modern fonts include the definition of what a “single spacing” actually is: the person who designs the font chooses the minimum space between lines so they do not “collide” with each other. This optimal size depends on the design of the typeface, how are stacked (yes, there are lan- guages in which a single letter can get several diacritics at the same time), the personal preferences of the author... Processors such as Writer use this parameter to decide what is a single spacing. Now, the problem with LATEX is that it was created decades before Uni- code, OpenType and all that. And that is why LATEX calculates the “single spacing” differently. The thing goes more or less like this: LATEX defines the “height” of a line as the size of the font. That means that a 10 pts font have a 10 points line height, and that is why “one and a half” (or 1.5, depending on where we look) is 15 pts, while “double” is 20. BUT, the single spacing is 12, not 10! Yes. Because a line spacing equal to the font size will give text that is too “compact” and unreadable, where the taller characters collide with the bottom of the previous line, LATEX automatically adds a 20% to this base height, but only to the single spacing, “one and a half” and “double” are calculated without this increase in size! And to make matters even worst, the custom line spacing is calculated from the single line spacing, the one that is augmented! I will ask you to remember the time at high school, where you worked with proportions and percentages. If we know that a quantity (the distance between two lines with “single spacing”) is the 120% of an unknown value and we want to calculate the 150% of that unknown value, what is the factor we need? Well 1 1,2 ⋅ 1, 5 = 1, 25 And if what we want is the double of that value, then 1 1,2 ⋅ 2 ≈ 1, 667 I tell you, LATEX can be strange... As you can see, the confusion arises from the fact that the options “one and a half” (or “1.5”) and double are defined from a different value than the used for “custom.” And yes, all this affects XƎTEX and LuaTEX too. More information about this: 88 Hyphenation

http://wiki.lyx.org/FAQ/Spacing http://tex.stackexchange.com/questions/13742/what-does-double- spacing-mean https://en.wikipedia.org/wiki/Leading

6.10 Hyphenation

When in a document the text is “justified” (both margins, left and right, form a straight line) we face a problem: if the text is distributed in columns or the font is large to have few words per line, the software that we use will be forced to vary the distance between words to fit the line to the margins, which gives blank spaces of unpredictable size that makes reading uncom- fortable. To avoid this, the fist line of action (we will see others in the next section) is the hyphenation of words at the end of the line in order to reduce those spaces... at the price of “cutting” many words. In general, LATEX do a great job finding a balance between the spaces and the number of hyphenated words, but only when the text area is “broad enough.” Is it possible to manually control how LATEX controls this feature? Well, yes, but that does not means you should try. Anyway, let’s see how LATEX works here. LATEX uses a complex algorithm to decide how to distribute the text in the lines of a paragraph. Simplifying the process a little (or a lot?), we could say that a parameter that measures “how bad a text looks like” is calculated and then LATEX tries to minimize that parameter in two attempts. In the first attempt it is calculated how bad the text looks like without hyphenation and if the value is good, then everything is fine. If the result is not good (and usually is never good), it repeat the process allowing hyphenation at the end of the lines. The “limiting value” that separates the “looking good” from the “look- ing ugly” is called “tolerance.” And since the process runs twice, we have two “tolerances,” one for the first attempt and the other for the second. These tolerances are controlled through the following instructions, to be written in the LATEX preamble:

\pretolerance= \tolerance= LYX, OpenType and typography 89 where is an integer between 0 and 10000. And is in that “value” where the whole process became “black magic:” the correct values for pretolerance and tolerance depends on the page size, the font, margins, number of columns... Trial and error. Lots of errors. Fortunately, most of the time LATEX hyphenates well, so don’t worry about this, it is not worth the effort. By the way, if in the PDF output you find a word wrongly - ated, it is possible to manually select the hyphenation point with Insert Formatting Hyphenation Point or Ctrl - . This is particularly important to know when writing in English, because LATEX tends to not hyphenate words that contain dashes: we need to manually hyphenate them.

6.11 Micro-typography

Before we start this section, a warning: this topic is purely about aesthet- ics. We will talk about how to make a LYX document even more beautiful. It does not have a real use and in fact most readers will not realize what is happening... which means that it was done right! But let’s go by parts.

6.11.1 What micro-typography means and its use

In the introduction of the microtype manual we find an inspired defini- tion

Micro-typography is the art of enhancing the appearance and of a document while exhibiting a minimum degree of visual obtrusion. It is concerned with what happens be- tween or at the margins of characters, words or lines. Whereas the macro-typographical aspects of a document (i.e., its lay- out) are clearly visible even to the untrained eye, micro-typo- graphical refinements should ideally not even be recognizable. That is, you may think that a document looks beautiful, but you might not be able to tell exactly why: good micro-typogra- phic practice tries to reduce all potential irritations that might disturb a reader. 90 Micro-typography

Perfect, the idea is to modify a text to make it looks better, but in such a subtle way that, in a first analysis, you cannot say why it looks better. How do we do that? Well, first of all we need to make a strong declaration: it is incredibly easy to fool our brains. Our “gray matter” fails quite often when evaluating lines and other graphical situations, as you can see in this wikipedia article on optical illusions: https://en.wikipedia.org/wiki/Optical_illusion And it is precisely a kind of op- tical illusion what we face when we see a “normal” justified text: ev- ery now and then we get the im- pression that the right margin is “wavy,” with “entries.” Just where you have marks and , the lines appear to be “dented,” even if this is not the case (you can check it with a ruler). The problem here is that points, colons and hyphens have “lighter weight” than the other characters and then our brain interprets them as “holes.” Figure 6.2: Protrusion example Now take a look at this text, at this book. The right margin seems more “straight” than a normal text, right? Wrong! As you can see with a ruler, colons, hyphens and points go slightly beyond the right margin. In this situation the edge seems more “full” and our brain interprets it as if the right margin is more “uniform”... even if it is not! The change is really subtle, but makes everything look a lot better. This micro-typography technique is called “protrusion” and is illustra- in figure 6.2: the gray line clearly shows that the punctuation marks go beyond the margin. There are other techniques, such as deforming the characters so that they occupy more or less horizontal space, thus controlling in this way the LYX, OpenType and typography 91 blank spaces between words. It is also possible to modify the space between characters (tracking)... many techniques.

6.11.2 How to apply micro-typography Do not even think about applying all this in a normal word processor like Writer or Word: it is impossible. It seems Scribus have some support to these techniques, but I have never used that software, so... we only have LATEX and derivatives with the microtype package, whose documentation is installed, in Linux, in /usr/share/texmf/doc/latex/microtype/microtype.pdf The manual has more than 240 pages, but don’t worry: in normal use, the default options are just perfect. To enable this package, in LYX 2.3 and later you only need to go to the font configuration menu and check the corresponding box. That’s it, nothing else to do. This works with normal LATEX, XƎTEX or LuaTEX, even if for the last two in a limited way: for example, at the time of writing this book, XƎTEX only offers protrusion support. If you want to know more, here some links http://hstuart.dk/2007/11/27/microtypography/ http://wiki.lyx.org/Tips/Typography https://en.wikipedia.org/wiki/Microtypography

6.12 Sub- and superscripts

I mean, sub and superscripts in the text, because in math mode it is quite easy: the for the subscript, the caret for superscript and that’s it. Now, entering sub and superscripts in text mode is also necessary, how can we do that? First, we need to distinguish between real and simulated sub and super- scripts. The real ones are specially crafted characters while the others come from reducing the font size and changing the vertical positioning. For ex- ample, in 2a²2 92 Sub- and superscripts

the first “2” after the a is a real superscript while the second has been simulated (the 2 before the a serves as reference). As you can see, real scripts looks better than simulated ones, with less contrast and fewer details, which increases readability. In fact, when you scale down a font you are also making the lines that define that character thinner, giving to the super and subscripts a “lighter” appearance. We have already seen how to apply OpenType tags: with +sups, +sinf or +subs we can get real sub and superscripts... the problem is that not all fonts offer such features beyond numbers and a few letters. So yes, we need to simulate them after all. To alleviate this problem it is convenient to choose a font with “optical sizes” such as Latin Modern, An- tykwa Połtawskiego, Coelacanth or, to a lesser extent, EB Garamond: sub and superscripts will be generated from the correct font and everything will look right. In LATEX, it is possible to use simulated sub and superscripts with the in- structions \textsuperscript{} and \textsubscript{}. For both LYX offers complete support: Insert Formatting Superscript/Subscript . By default LYX does not offer keyboard shortcuts for these options, but we have already seen how to solve this situation (section 3.2): we only need to know the correct “codes” for both functions. For a superscript it is:

script-insert superscript while for a subscript is:

script-insert subscript

Note: If we have a particularly complete font with all the sub and superscripts we need, there is a package (there is al- ways a package) that each time it finds a \textsuperscript or \textsubscript command, it replace them with the corre- sponding OpenType options. This interesting package has the cool name realscripts, but I will not talk about it here: its documentation is really simply (six pages). But be aware that this package can be “dangerous:” if a character is not sup- ported by the font used, the results can be really bad. LYX, OpenType and typography 93

Now, how can we set the reduction factor and the change in vertical posi- tioning? For this, we need to use pure LATEX code inside one of those “TEX boxes.” The instruction to be used is \raisebox and it works like this

\raisebox{}{} where indicates the vertical displacement and is what we need as sub or superscript. The value can be positive (to move up) or negative (to move down) and can be expressed in any measure unit. For example we can use

\raisebox{6pt}{superscript} \raisebox{-6pt}{subscript} to obtain (the first) a superscript at 6 points above the base line and a sub- script (the second) at 6 points below the base line. For the careful typographer, we can also use units like “ex.” Basically, 1 ex is a value equal to the height of a lowercase character without ascenders or : for example, the height of a “x.” We could then use

\raisebox{1ex}{superscript} to make the superscript go up to the “roof” of the lower characters. Now, the \raisebox does not change the size of the text, so we have to use some “nested instructions”

\raisebox{1ex}{\scriptsize{superscript}} gives us a superscript with a “scriptsize” size (we have talked about the size of LATEX fonts in section 5.3) at a height of 1 ex over the base line. In principle, to use this code we need two “TEX boxes,” one before and the other after. By writing

base {\raisebox{1ex}{\scriptsize{ superscript }}

we get 94 Sub- and superscripts

basesuperscript

I know, I know, writing all this every time... But don’t worry, in chapter 8 we will see how all this can be simplified with the use of “local layout.” Chapter 7 Footnotes and endnotes

Here we will talk about how to change the presentation and behavior of footnotes in a LYX document and how to use endnotes. For all this we need the package texlive-yafoot. Several commands mentioned in this chapter accept parameters, but I will not comment on them. In general, the default values are enough, so it is up to the reader’s curiosity to delve in the documentation.

7.1 Notes numbers without superscript

By default, in LATEX and derivatives, not only the footnote anchor is pre- sented as a superscript, but also the number in front of the note itself. One way to change that is to add the following code to the LATEX preamble: \makeatletter \renewcommand\@makefntext[1]{% \noindent\makebox[0pt][r]{ \@thefnmark.\space}#1} \makeatother Here we are redefining the “mark” of the footnotes, making them without indentation (noindent), with the number on the right (the r) of a “box” (makebox) aligned to 0 pt of the margin (therefore, hanging inside the left margin) while the number itself (@thefnmark) is not formatted. Lots of deep code here!

95 96 Footnotes in columns

7.2 Footnotes in columns

Suppose we have several footnotes, but they are all very short (for example, to indicate the page number in the reference). In such situation, it might be interesting to show the footnotes in two columns, even if the main text does not have columns. For this, we write in the LATEX preamble

\usepackage{dblfnote} and that’s it. The only thing to keep in mind is that on the last page of the chapter, whenever it is half empty, the footnotes will fill the first column before moving on to the second.

7.3 Footnotes without paragraph breaks

If using two columns is not enough to save space, we may consider putting all footnotes on the page within the same paragraph. For this, in the LATEX preamble we have to write:

\usepackage[para]{footmisc} and everything will be ready.

7.4 Restart footnote numbering on each page

It is enough to add, in the LATEX preamble, the following code

\usepackage{perpage} \MakePerPage{footnote}

The first line declares the use of the perpage package, which is used to restart the numbering of different counters, while the second line indicates which we want to reset (that of footnotes). Footnotes and endnotes 97

7.5 “Numbering” footnotes with symbols

Suppose we want the following substitution: 1 → ∗ (LATEX command: \ast) 2 → † (LATEX command: \dagger) 3 → ‡ (LATEX command: \ddagger) 4 → § (LATEX command: \S) 5 → ∗∗ etc. It is important to keep in mind that “numbering with symbols” only makes sense if we have few footnotes and we restart the numbering on each page. This should be possible to do with the footmisc package, but for some reason it does not work for me, so here I will present an alternative that, although a bit more complicated, always works. In the LATEX preamble we have to write:

\def\mysymbols#1{\@mysymbols{\@nameuse{c@#1}}} \def\@mysymbols#1{\ifcase#1\or $\ast$\or $\dagger$\or $\ddagger$\or $\S$\or $\ast\ast$\or $\dagger\dagger$\or $\ddagger\ddagger$\or $\S\S$ \else\@ctrerr\fi} \def\thefootnote{\mysymbols{footnote}} \usepackage{perpage} \MakePerPage{footnote}

The first line defines a new instruction called \mysymbols. The second line set this instruction indicating the substitutions discussed above. The third line redefines the \thefootnote instruction to make use of the substitu- tion that we defined. The last two lines must be at the end and apply the perpage package as discussed in the previous section. It is important to keep in mind that if we try to use more footnotes in a page than the number of substitutions that we defined, LATEX will give an error, so better define more symbols than we possible need: it is enough to add another “\or $\symbol$” to the list in the second line of the code. The inspiration for this section: 98 Change the footnote font

https://groups.google.com/d/msg/comp.text.tex/ QZrTF7tzo5k/TvT_RsCyBfsJ

7.6 Change the footnote font

By default, in a LATEX document footnotes use the same font as the main text, but in a size, wait for it, footnotesize. To modify the font that the footnotes use, we can use the footmisc package (for this, it works). As always, in the preamble (we are using, as always, XƎTEX)

\newfontfamily{\kley}[]{Kleymissky} \usepackage{footmisc} \renewcommand*{\footnotelayout}{\small\kley}

In this code we created a new font family based on Kleymissky1, and patched the footnote command to use that font family for the footnote (I am not rec- ommending it, you know, all this is just for the sake of the example) chang- ing the size to small. Note 1: This works fine with everything discussed in the pre- vious three sections, but not with what was presented in the first section of this chapter. You know, conflicting packages... Note 2: (corollary of the previous note) with this, the font of the footnote label will not be changed.

7.7 Endnotes

LYX offers graphical support for the endnotes package. To use it, we need to go to Document Setting Modules 2 to activate the “endnotes” module. Now, to insert an endnote in the document we need to go to Insert Custom Insets Endnotes and write the note text in the box. Finally, to show the endnotes in the document, we need to insert a TEX box with the following code

1. http://www.glukfonts.pl/font.php?font=Kleymissky 2. We will come back to the modules in chapter 8. Footnotes and endnotes 99

\renewcommand{\notesname}{Endnotes} \theendnotes

The first line provides a name to the “section” used by the endnotes, while the second line inserts the list of endnotes. Something interesting with this system is that it is possible to insert these instructions as many times as we want in the document, so it is possi- ble to have endnotes grouped by chapter, for example, instead of all together at the end. In this situation, is maybe convenient to reset the endnotes num- bering each time, adding the following instruction to the previous code

\setcounter{endnote}{0}

7.8 An extra: margin notes

LYX offers support for inserting margin notes: we simply go to Insert Margin Notes and get one. Hi! However, there are not many ways to change the margin notes format- ting from the graphical interface, so we have to use the famous “TEX boxes” instead. For example, the margin notes are placed in the “external” margin, but that can be easily changed by inserting a TEX box with the code

\reversemarginpar{}

To go back to “normal,” in another TEX box it is enough to write:

\normalmarginpar{}

LYX uses the default LATEX implementation of margin notes, which has some limitations. To use the marginnote package, which is more powerful, we need to add to the LATEX preamble

\usepackage{marginnote} \let\marginpar\marginnote 100 An extra: margin notes

At this point, I must confess something: I am not a big fan of margin notes3 so I will not delve into this topic. The LYX documentation on this topic found in Help Embedded Objects section 4.3 contains a lot of informa- tion.

3. In fact, I hate them. Chapter 8 Modules, local format and math macros

Another amazing feature of LYX is that it can be extended. In this chapter, we will see how to add features, the correct way to define formats that are not present in the document class used and how to create some “tricks” that will help us to write complex math expressions with easy.

8.1 Modules

In chapter 7 we mentioned the “modules:” under Document Settings Modules (figure 8.1) we have a long list of new functions waiting to be en- abled in our document. These modules simplify the use of several LATEX packages. Talkingabout all of them is impossible, but in the following chapters we will see some of them: for now, I let you play with the options. Now, is it possible to add another module that is not offered by default? Of course! Let’s see how. On this page of the LYX wiki http://wiki.lyx.org/Layouts/Modules it is possible to find several modules ready to be used. We have mod- ules that add new functionalities (comments, indexes of names, formats), integration with the Sage program, changes to the format of different doc- ument classes, etc.

101 102 Modules

Figure 8.1: Enabling modules Modules, local format and math macros 103

Toinstall any of these modules, after downloading the *.module we just have to copy it to the “layouts” folder in the user profile of LYX. In Linux you find that folder in ~/.lyx/layouts/ Always remember to Reconfigure the program after installing anything!

8.2 Create new instructions

We have already created some instructions when defining a font family in section 6.2. But maybe we need more: for example, to have a “shortcut” to insert some fixed text or even create a “function” that formats a particular element in our document. Todo so, we need to define a new instruction with \newcommand{}[]{}. This command must be used in the LATEX preamble as follows:

\newcommand{\mycommand}[]{}

Let’s suppose we want to create a new instruction to insert some text as su- perscript using the raisebox command. Here, \mycommand is the name of the new instruction, for example \goup, in- dicates how many parameters are needed by the command, in this case 1, whereas in we have to write everything needed to create the command, calling each parameter with # (#1 for the first parameter, #2 for the second, etc.). Then, the code to be inserted in the LATEX preamble is

\newcommand{\goup}[1]{{\raisebox{1ex}{ \footnotesize{#1}}}}

To use this instruction inside LYX, we open a first TEX box with Ctrl L , write \goup{, leave the box to write the text to be superscript and finally create a second TEX box with a closing }. In this way, we can see something similar to this in LYX base \goup{ superscript } but in the PDF output we will get 104 Create character styles in LYX

basesuperscript Wecan use more parameters, or even none. In that last case, the instruc- tion would be of the form

\newcommand{\mycommand}{}

Done! Well, not quite, this is still not practical. But we are ready for the last step! Finally, we will see how to do this and more in the best LYX style.

8.3 Create character styles in LYX

In LYX it is possible to apply some predefined character styles quite easily, such as “” (with Ctrl E , by default it gives italics), bold ( Ctrl B ) or small caps ( Alt C , then C ), but not much more. By enabling the “Logical Markup” module we have a couple more, available with a right click Text Style or in Edit Text Style . Now, if we want to create a different one? We might need a simple way to activate a particular OpenType fea- ture instead of using a cumbersome set of TEX boxes, or a way to write less when we use the hologo package we presented earlier. Note: Remember that, for the second example, you need to write \usepackage{hologo} in the preamble!

Let’s go to Document Settings Local Layout . There we have to write something like:

Format 66 InsetLayout Flex:HistoLig LyxType charstyle LabelString histolig LatexType command LatexName histolig Preamble \newcommand*{\histolig}[1]{{% \addfontfeature{Ligatures=Historic} #1}} EndPreamble Modules, local format and math macros 105

Figure 8.2: Create a “local layout”

ResetsFont true End

InsetLayout Flex:LogoTipo LyxType charstyle LabelString HoLogo LatexType command LatexName loguito Preamble \newcommand*{\loguito}[1]{{\hologo{#1}}} EndPreamble ResetsFont true End

Notes: 106 Create character styles in LYX

• Before anyone asks, the Format 66 at the beginning indicates the version of the local layout system being used by LYX 2.3.x (in 2.2.x it was 60). This first line is mandatory, but we only need to use it once if we define several “local layouts.”

• After the colon in the second line, there is NO space. This line defines the name of the new format.

• LyxType defines the type of format we are creating: in the example, a character style (charstyle).

• LabelString is the label we will see during editing in the LYX win- dow, tagging the applied format.

• LatexType defines that we are applying a command, either a base command or, as in the example, a custom one.

• LatexName is the name (without the initial backlash) of the LATEX command to be applied.

• If we want our style to look different during editing, we can change the font used with something like the following code: Font Family Serif Shape Italic EndFont

• The part between Preamble and EndPreamble can be used to define code that should go to the LATEX preamble. Clearly, if that code is already in the preamble, we do not need to rewrite it here!

• ResetsFont indicates that the format must be applied only to the selection.

• Before applying the code, we need to “validate” it: only if LYX con- firms that everything is OK, we can go ahead.

• It is also possible to create “environments:” more details in Help Customization section 5.3.7 and in the example below. Modules, local format and math macros 107

Now we just have to select the text that needs the style, and right click Text Style HistoLig . What can be seen in the LYX window as this is a non historical text this is an historical standard this another non histolig historical text

in the output it will look like this: this is a non historical textthis is an historical standard this another non historical text

while XeTeX AmS HoLogo HoLogo will give: XƎTEX AMS To erase an already applied text style, it is enough to do a right click Text Style Dissolve Text Style In subsection 15.1.2 we will see another example of local layout while in the appendix B you will find the definition of all local layouts used in this book.

8.4 Paragraph environment?

Just a quick and unexplained example that provides a paragraph environ- ment with a background color and border. It uses the mdframed and xcolor packages that, of course, need to be installed:

Format 66 Style MyParagraph Category MainText Margin Static LatexType Environment LatexName myparagraph NextNoIndent 1 LeftMargin MMM RightMargin MMM 108 Math macros

ParIndent MM ParSkip 0 ItemSep 0 TopSep 0.5 BottomSep 0.5 ParSep 0 Align Block AlignPossible Block, Left, Right, Center Preamble \usepackage{mdframed} \usepackage{xcolor} \newenvironment{myparagraph} {\begin{mdframed}[ backgroundcolor=lightgray, linecolor=lightgray ]\quotation} {\endquotation\end{mdframed}} EndPreamble End

Try to understand it! Just play a bit with the parameters. It’s fun!

8.5 Math macros

Let’s consider two situations: Situation 1: we may have a complex mathematical expression that we need to repeat, with slight variations, several times in the same document. For example, we could be writing an essay on Fourier transforms, and that means entering several times an expression where only the function to be transformed is different, not the rest of the integral.

Situation 2: LYX cannot provide graphical support for each and every one of the possible LATEX commands, so we may need to write some code directly, code that may appear “strange” during edit- ing. Modules, local format and math macros 109

Affronting any of this situations imply a lot of extra work, lots of com- piling and adjusting... or not, or not always. Welcome to one of the most interesting, but least known, LYX features: the math macros. The idea is that we create a “macro” with the necessary LATEX instruc- tions (the fixed part of the expression), the “arguments” needed (the chang- ing part) and give it a name. Once the macro is ready, we just need to call it from anywhere in the document using its name, and then it is just a matter of filling in the gaps. With each new version of LYX, the Situation 2 is increasingly rare, because the remaining unimplemented commands are the most “exotic.” We will address here the Situation 1 instead: in the process, everything will result clear. For this, we will use the mathop command. This command converts any sign or text into an “operator” that accepts limits. To use it normally, you need to: 1. In math mode, select the “Style and classes” menu in the math tool- bar and then “large operator class” 2. Insert a character to act as operator 3. Exit that box 4. With the underscore and the caret, write the limits So, let’s try to simplify the process. First, we have to go to Insert Math Macro , that something similar to what is shown in figure 8.3 will appear. As you can see, the tool opens a “box” that can be used to create our macro, while below we have, in addition to the normal toolbars of the math editor, a new one to create or delete parameters, make them optional, etc. Note: This box will not appear in the compiled document, so you do not need to worry about its presence. In fact, it could be anywhere in the document, but it is better to group all our macros in a place where we can find them quickly.

Now we replace newmacroname with something more comfortable. Since this example is about using the \mathop command, we can call it mop. 110 Math macros

Figure 8.3: Creating a math macro: on top, the beginning of the process, below, how you can see everything in the LYX window, with the expression waiting for the parameters to be filled Modules, local format and math macros 111

Important: Be careful with the chosen name, we cannot use a valid LATEX command!

In the first of the two “sub-boxes,” the one marked “TeX,”we need to write our LATEX code while in the second, the one marked as “LyX,” what we want LYX to show during the use of the macro. Since \mathop has graphical support, we simply write the same in both boxes. And it is here where we can see how to solve the Situation 2: in the second box we do not write the same as in the first one, but something that helps us understand what we will get in the output. Remember that in the LYX math editor, the easiest way to enter the {} delimiters for grouping expressions is by typing \{ (the closing brace will appear automatically). Now we need to use the new toolbar to add the necessary number of parameters, in this case three, and we apply to them the needed commands (\mathop to the first one, subscript to the second and superscript to the third one), which gives us what you can see in the lower part of figure 8.3. And that’s it. To use our great macro, we just need to write, inside the math editor

\mop and press the space bar once. Now we have the three boxes waiting for con- tent. Finally, with an equal sign in the first parameter, leaving the second empty and writing “def” in the third, or writing the sum for 푖 and 푗 from one to 푁 in the first parameter, 푖 > 푗 in the second and leaving the third empty, in the compiled document we will see (remember that the box with the macro definition will not appear)

푑푒푓 푓 (푥) = ln(푥)

푁 ∑ 퐴푖푗 푖,푗=1 푖>푗 112 Math macros

We can “nest” our expressions, or, as we see, leave some parameters empty: the only limit to solve problems is our creativity. And that’s it! As you can see, dear reader, math macros in LYX are a incredible powerful tool that is really easy to use, now that you know its existence, start using it! Chapter 9 Numbered lists

Let’s suppose we want to build a numbered list in a LYX document, but that we need to number it with Roman numerals or even alphabetic charac- ters. Searching through internet we can find some LATEX tricks to introduce some difficult to read code in the preamble, tricks that are neither simple nor perfect. In this chapter, we will discuss how to modify a particular list and then how to obtain several lists in our document using the same format.

9.1 Modify particular lists

For this work, LYX offers an alternative that, although it is not perfect, is simple and robust. The fist thing we must check is that our LATEX distribution has the pack- age enumitem already installed. Then, in our document we go to Document Settings Modules , select Customisable Lists (enumitem) and press Add. Now we have to go to the beginning of the first line in the numbered list and select the menu Insert Enumerate Options . In the box, we have to insert a “TEX box.” Within this nested box, we need to write the instruction to change the numbering. For example, if we want the numbering to be with Roman numerals in uppercase and without separator, the code must be

\label=\Roman{enumi}

113 114 Change all lists in the document

For lowercase Roman numerals, we change \Roman for \roman, to use al- phabetic characters, we use \Alph for uppercase and \alph for lowercase while \arabic will give us normal numbers. If our list has several levels and we want to change all of them, we must use the label instruction in each one. For example, to obtain a first level with Roman numerals and the second with alphabetic characters, showing both in the second level, we need to use

\label=\Roman{enumi}.\alph{enumii} as “numbering option” in the first instance of the second level. As you can see, the second level is written as enumii, duplicating the final “i.” This can be extended to any level, adding another “i” for each modified level... but only up to level 3! In the fourth level we need to use enumiv. Yeah, lowercase roman numerals. Another thing to consider in the example is the addition of the separa- tor (in this case, a period). Unfortunately, the double box with the label instruction should be included again each time a sublevel is restarted in the list. Because you need to perform this operation every time, for each level in each list, this is not precisely comfortable, but at least it works.

9.2 Change all lists in the document

Now I am going to present a method to modify several lists at the same time. Suppose we need each level of the list to show the number of the upper level in addition of its own number to obtain something like

I First level

I.A Second level I.A.1 Third level I.A.2 Another second level I.A.2.a Fourth level Numbered lists 115

That’s it, the first level with roman numeral in uppercase and bold, the sec- ond with uppercase alphabetic characters, the third with numbers and the fourth with lowercase, italic letters, each level showing the numbering of the upper level. Inserting a TEX box at the beginning of the document (or at least, before the first list), we need to write something like

\renewcommand{\theenumi}{\Roman{enumi}} \renewcommand{\labelenumi}{\textbf{\theenumi}} \renewcommand{\theenumii}{\Alph{enumii}} \renewcommand{\labelenumii}{\textbf{\theenumi}. {\theenumii}} \renewcommand{\theenumiii}{\arabic{enumiii}} \renewcommand{\labelenumiii}{\textbf{\theenumi}. {\theenumii}.{\theenumiii}} \renewcommand{\theenumiv}{\alph{enumiv}} \renewcommand{\labelenumiv}{\textbf{\theenumi}. {\theenumii}.{\theenumiii}. \textit{\theenumiv}}

Note: For presentation reasons, in the text I introduced line breaks after the separators in the scheme of each numbering, but this will introduce a space between the numbers whenthe document is compiled. The lines that define the numbering for each level must be written without breaks. Moral: never copy and paste LATEX code without thinking what you are doing.

Wehave already discussed the \textbf, \textit, \Roman, \alph, etc. com- mands (chapter 5), so I think you will have no problem understanding how to modify those lines. But, what about the other LATEX commands? Well, without going into details about \renewcommand, let’s focus on the commands \theenum and \labelenum. As you can see, the code of those commands is followed by i, ii, iii and iv to indicate the level in the num- bered list (lowercase roman numerals again). \theenum defines the type of numbering and \labelenum what is shown for each level. 116 Change all lists in the document

Cross-references (inserting a label into an element and then calling it somewhere else) work... sort of: the type of numbering is keep, but the separators will be missing. Clearly, if we only need that each level displays its number and not the numbers of the previous levels, it is enough to delete the unnecessary code. Something like:

\renewcommand{\theenumi}{\Roman{enumi}} \renewcommand{\labelenumi}{\textbf{\theenumi}} \renewcommand{\theenumii}{\Alph{enumii}} \renewcommand{\labelenumii}{\textit{\theenumii}} \renewcommand{\theenumiii}{\arabic{enumiii}} \renewcommand{\labelenumiii}{\textit{\theenumiii}} \renewcommand{\theenumiv}{\alph{enumiv}} \renewcommand{\labelenumiv}{\theenumiv} should work. In this case, cross-references should work without trouble. The assigned format will be valid until the end of the document, or until we insert a new TEX box with a new format. Chapter 10 About the Table of Contents and other Indexes

Setting up an index is perhaps one of the darkest points in LATEX lore. In this chapter we will provide a brief introduction to some tools used to solve specific issues related to indexes. From now on, we will refer to the “table of contents” as TOC.

10.1 Short titles

Let’s start with something simple: what if the chapter or section title is too long and we need the TOC and document headers to present a shorter ver- sion? With the cursor in the title: Insert Short Title , or with the mouse right click Short Title or, for the keyboard fans, Alt A , then 1 . The box that appears will give us the opportunity to write a shorter version of the title, which will be used by the TOC and the cross-references, overwrit- ing the “real” title.

10.2 Partial TOCs for each chapter

In the LATEX preamble, we have to write

\usepackage{minitoc}

117 118 Correct the spacing in lists of figures and tables

(obviously, the texlive-minitoc package must be installed). In the doc- ument, just before the general TOC, we need to insert a TEX box with the command

\dominitoc

Finally, for each chapter, just after the chapter name and before any section we need to insert another TEX box with the command

\minitoc

10.3 Correct the spacing in lists of figures and tables

When an article document class is used, figures are numbered in sequence without interruption, while in book format the numbering is usually .. In LYX it is really simply to activate a numbering scheme by sections, which is presented, in articles, as

. while in books it is .
.: it is enough to go to Document Settings Modules (we talked about modules in chapter 8) to enable “Number Fig- ures by Section.” The problem with all this appears in a book document class when we create a figure index: the number occupies more space than allowed by the default configuration and the numbers “collide” with the text that follows. Tofix the space between the number and the text, in the LATEX preamble we have to write

\makeatletter \renewcommand*\l@figure{\@dottedtocline{1}{ 1.5em}{3em}} \makeatother

Tochange the distance, it is enough to play with the {3em} value to the right of the central line. To do the same with the table index, we need to add About the Table of Contents and other Indexes 119

\renewcommand*\l@table{\@dottedtocline{1}{ 1.5em}{3em}} between \makeatletter and \makeatother and that’s it. To learn more about this topic: http://tex.stackexchange.com/questions/133747/ reduce-space-between-table-number-and-title-in-list-of-tables http://tex.stackexchange.com/questions/87019/ list-of-figures-numbers-overlap-image-caption

10.4 Avoid dotted lines in indexes

By default, many document classes use dotted lines as “guides” between the title text and the page number in the indexes. Let’s suppose we want to eliminate those lines. In the LATEX preamble, we add

\renewcommand{\@dotsep}{10000}

Done. This command will apply to all indexes and TOCs in the document. What happens here is that the command \@dotsep controls the separa- tion between the dots, so if instead of 10000 we use values like 20 or 30, we will simply get dots with greater than normal separation. The value 10000 is special in LATEX and it is used to indicate “infinity” in any command that needs a numeric parameter, so in the case discussed here, 10000 deactivates the dots.

10.5 Some (few) words about alphabetical indexes

In LATEX there are several ways to generate alphabetical indexes and you can use any of them in LYX. In LYX we can choose between makeindex, texindy or xindy. If you have no idea what I am talking about here, dear reader, do not worry: it is normal. This is a really complex topic that requires some study before mak- ing use of it. This means that talking about alphabetical indexes in detail 120 Some (few) words about alphabetical indexes goes beyond the general scope of this book, so I will just indicate the bare minimum. The curious reader can delve into the LYX user guide (section 6.6) or the many LATEX manuals available on-line to know more. To mark a word or text to be included in an alphabetical index, we just have to select it and go to Insert Index Entry . This gives us a “box” with a label right after the marked text. By default, the box content is the same as the selected text, but we can change it without problems. The alphabetical index can be introduced anywhere in the document with Insert List / TOC Index List . Unlike the TOC, when clicking on the “button” nothing happens, but it is possible to set the preferences for the “processor” at Document Settings Indexes . There, in addition to choos- ing between makeindex, texindy or xindy we can pass options to those processors, set the creation of more than one index (one of words, another for names, etc.) and administrate existing indexes. Chapter 11 Headings

In this chapter we will see how to change the presentation and numbering of the titles of our document, be these the “parts,” “chapters,” “sections,” etc. We will slowly move from the easy topics to the more complex ones. Let’s start with it.

11.1 Rename the “Part” and “Chapter” environments

Let’s suppose we want to write a book with LYX and set up our document to use the “Book” document class. This gives us several environments, among them “Chapter” (LATEX com- mand \chapter{}) to separate the different topics of our book and “Part” (LATEX command \part{}) to group chapters. But suppose that instead of “Parts” we want to divide our book in, well, “Books” and that instead of “Chapter 1: Chosen title” we want “Day 1: Cho- sen title.” Can we rename these environments? The simplest way is to go to the LATEX preamble and add some code:

\usepackage[english]{babel} \addto\captionsenglish{ \renewcommand{\partname}{Book} \renewcommand{\chaptername}{Day} }

121 122 Number chapters with Roman numerals

Basically, we are cheating: we are telling LATEX that it needs to “translate” the predefined values for Part and Chapter, using the ones we want. In fact, if we leave the second braces empty, writing

\renewcommand{\partname}{} we will only get the number and the title, without labels. In the LYX window nothing changes, but the PDF output will show what we want to see.

11.2 Number chapters with Roman numerals

To change the “style” of the chapter numbering into roman numerals, we need to modify the “counter” used for the chapters by adding to it “some formatting,” and for this we need the renewcommand command:

\renewcommand{\thechapter}{\Roman{chapter}}

To use uppercase letters we simply change Roman for Alph, as we have seen in chapter 5.

11.3 Make the chapter start at any page

By default, in the book document classes, chapters always start on a new page that is also a “right” (odd) page. To those who missed the quick com- ment in chapter 4, to make chapters start on any page, left or right, simply go to Document Settings Document Class Class Options Custom to write

openany

11.4 Avoid page breaks at the beginning of a chapter

It is not like I like this, but you know, just for the sake of completeness. Let’s suppose that for any reason we want to completely avoid page breaks at the beginning of each chapter. In this way, chapters will start on the same page the previous one ended. To make this possible, we need to Headings 123 redefine the chapter environment, therefore, going to the LATEX preamble, we write

\makeatletter \renewcommand\chapter{% \global\@topnum\z@ \@afterindentfalse \secdef\@chapter\@schapter} \makeatother

I have seen this code here: http://compgroups.net/comp.text.tex/ latex-report-class-page-break-after-every-chapt/1924905

11.5 Change the format of titles in LYX documents As we have said many times, the document class determines the general ap- pearance of the document and that includes how the different headings (chapters, sections) look like. In the vast majority of document classes, the headings use the same body text font, while some document classes use the “sans” font family. That is generally fine, but what if we want to change this format? Or even choose a different color? Or add “special effects”? For example, we might want a “box” surrounding the title, as we see in this book. There are several methods to achieve these changes and some document classes like Koma Script offer tools that make many of those things possible, but the option I present bellow is perhaps the most general possible (even if it is not completely general: it does not work with the document class Memoir).

11.5.1 The packages needed Generally, they are installed by default, but it is always a good idea to check if the xcolor and titlesec are available in our LATEX distribution. The xcolor documentation is installed, in Linux and with TEXLive, in /usr/share/texmf/doc/latex/xcolor/ 124 Change the format of titles in LYX documents

while titlesec documentation is installed in /usr/share/texmf/doc/latex/titlesec/ Here I will only give general indications about these packages. These indications will be more than enough in most cases, but for more extreme uses, you can always read the... manual.

11.5.1.1 xcolor

The xcolor package is used to define, yes, you guessed, colors. The easiest way to use it is to declare it in the LATEX preamble with, for example

\usepackage{xcolor} \definecolor{PaleBlue}{rgb}{.3,.5,.7}

The first line declares that we want to use the package in our document, while the second defines a color: the parameters between braces are, respec- tively, the color name, the definition method and the “values” for each pri- mary color in the form of three numbers between zero and one (how much red, green and blue), separated by commas.

11.5.1.2 titlesec This package offer several instructions for making changes to titles. It can be used in two ways, “simplified” and “complete.” The simplified way can only be used by sections, subsections and lower levels, while for the Part and Chapter environments (or to obtain full power) we need to use the complete form.

11.5.2 A complete example

In the LATEX preamble:

\usepackage{titlesec} \usepackage{xcolor} \definecolor{PaleBlue}{rgb}{.3,.5,.7} \definecolor{Greeeeen}{rgb}{.3,.7,.3} \newfontfamily{\coral}{TeX Gyre Chorus} Headings 125

\titleformat{\chapter}[frame] {\LARGE\coral\color{PaleBlue}}{ \filright\chaptertitlename\ \thechapter}{20pt}{\Huge} \titleformat*{\section}{ \Large\bfseries\sffamily \color{Greeeeen}}

The first two lines declare the use of titlesec and xcolor packages. Then, two colors are defined, PaleBlue and Greeeeen (no, it’s not a typo). The fifth line defines a new font family to use in the document. We talked about that in the section 6.2. In the example you can see both, the simplified and the complete form of \titleformat, part of titlesec package. The starred form is the “simplified” one and has been used to quickly define the format of the sections: applied to the \section environment, it uses the sans font defined in the document (\sffamily), in bold and with its size set as \Large, assigning to it the color Greeeeen we have defined. The complete form is used to modify the \chapter environment. It starts indicating that a frame must be built around the title ([frame]: if you do not want a frame, it is enough to write [display] instead). Then, we have the size defined as \LARGE for the label (the wofrd “Chapter” followed by the number), the coral font family and the PaleBlue color. Then, there is a series of formatting instructions that begin with “align to the right,” provide structure to the information (including a space between the label and the title text) and end indicating that the title text must have the size \Huge, which is definitely larger than the label. We can see the result of these instructions in the screenshot of figure 11.1. Clearly, this can also by done for the “part” environment, adding for example:

\titleformat{\part}[display] {\huge\cormorant}{\filright\partname\ \thepart}{20pt}{\Huge} 126 Restart the numbering after a “Part”

Figure 11.1: An example of titles modified with the use of titlesec

Here we did not use the frame and a larger size was chosen for the label (also using another font, defined elsewhere). And that’s it: all the basic ingredients are there, and we just have to compile the document. As we have said, all these instructions have more options, but I leave you with the details: that is what the documentation of each package is for.

11.6 Restart the numbering after a “Part”

By default, LATEX does not restart chapter numbering after a Part, giving a continuous numbering:

• Part I

∘ Chapter 1 ∘ Chapter 2

• Part II Headings 127

∘ Chapter 3

I prefer this default option, but it is possible and perfectly valid that someone needs to use the opposite, that’s it

• Part I

∘ Chapter I.1 ∘ Chapter I.2

• Part II

∘ Chapter II.1

The simplest way to achieve this is with the package chngcntr. In TEX Live it is installed as

texlive-chngcntr texlive-chngcntr-doc

The documentation, in Linux, is in /usr/share/texmf/doc/latex/chngcntr/chngcntr.pdf It is only two pages. To use this package, in the LATEX preamble we have to write

\usepackage{chngcntr} \counterwithin{chapter}{part}

The first line declares the package while the second says that chapter must be counted inside part, and that means that it must restart its numbering each time part changes. Ready, right? Well, no: by adding the “part” to the chapter number- ing (and figures, and tables) we have problems with the index, because the number runs out of space and crash with the text of the title. In chapter 10 we discussed how to solve this problem for the list of figures and tables, so following that example, after the two line of code presented above, we should add the following: 128 Restart the numbering after a “Part”

\makeatletter \renewcommand\l@chapter{ \@dottedtocline{2}{1.5em}{3em}} \makeatother

To add space in the index lines corresponding to the sections, we must duplicate the above code, but changing l@chapter by l@section:

\makeatletter \renewcommand\l@chapter{ \@dottedtocline{2}{1.5em}{3em}} \renewcommand\l@section{ \@dottedtocline{2}{1.5em}{3em}} \makeatother

And so on with subsections (subsection), etc. OK, now it is ready! But that is not something you will see on this book. Chapter 12 Headers and footers, and page styles

To modify headers and footers in LATEX (and derivatives) documents, we need to use the fancyhdr package. LYX offers partial support for it in its in- terface, but in order to get the full power we will need to take a deep breath and start to write code in the LATEX preamble. Headers and footers are associated to page styles, something we will dis- cuss at the end of this chapter. Therefore, we will start talking about how to change the header and footer content in the “text body” to only then move into the topic of the creation and use of custom page styles.

12.1 Preparations

The fancyhdr documentation is installed, in Linux and with TEXLive, in /usr/share/texmf/doc/latex/fancyhdr/ By default, LATEX documents are set up as “single sided” pages, so if we want to use both sides of the paper, we must tell LYX in advance. And also enable the fancyhdr package, of course: it is enough to go to Document Settings Page Layout and, as you can see in figure 12.1, for “Page style” se- lect “fancy” and also check the “Two-sided document” option. Now, we can move on to the LATEX preamble and start typing... but before that, a brief introduction to what can be written.

129 130 The fancyhdr package

Figure 12.1: Enabling fancyhdr

12.2 The fancyhdr package

The fancyhdr package is used to change the content of the headers and footers of a page. Both sectors are divided into three parts: left, or l/L, cen- tral, or c/C and right, or r/R. There are two ways of using this package. The simplest way, useful for “one sided” documents, is with the commands

\lhead{content of the left header} \chead{content of the central header} \rhead{content of the right header} \lfoot{content of the left footer} \cfoot{content of the central footer} \rfoot{content of the right footer}

Below we will see some examples of valid “content.” Wecan get the full power of this package with the command \fancyhead for headers and \fancyfoot for footers, using the following conventions R represents “right” Headers and footers, and page styles 131

L represents “left”

C represents “center”

O represents odd pages

E represents even pages

The instruction

\fancyhead[RO,LE]{CONTENT} will put CONTENT to the right on odd pages and to the left on the even pages. If we write

\fancyfoot{} the footer will be empty. Now, what kind of CONTENT can we use? For sure, simple text it is perfectly fine. In fact, if we use XƎTEX and have defined a new font family (as we have seen in section 6.2) it is possible to use text as “strange” as we want (bellow, an example). We also have the commands to insert the page number and the chapter name/number. For example:

\thepage inserts the page number, while

\leftmark \rightmark are used to provide information about the chapter/section in use (see exam- ple).

Note: if for some reason the information is not available for any of those “marks” (for example, in a given chapter we do not have sections), a blank space will be left instead. 132 An example

In general, the chapter name will be set to uppercase. To avoid that we need to use the \nouppercase{} command (we will see how that works in the example). It is important to keep in mind that you should be care- ful with this instruction if you have Roman numeral: they will turn into lowercase... Yes, LATEX can be weird. Using these commands, a separation line will be added. To modify its width we can use

\renewcommand{\headrulewidth}{0.4pt}

Writing 0pt (zero points), the line will disappear.

12.3 An example

Let’s put everything together:

\newfontfamily{\coral}{TeX Gyre Chorus} \renewcommand{\headrulewidth}{0.4pt} \fancyhead[RO,LE]{\thepage} \fancyhead[LO]{\nouppercase{\leftmark}} \fancyhead[RE]{\coral{El pingüino tolkiano}} \fancyfoot{}

Here we have the page number to the right in odd pages and to the left on even pages, the chapter name to the left on the odd pages and the text “El pingüino tolkiano,” formatted with the TeXGyre Chorus font, to the right on even pages. Now, the command \leftmark writes “Chapter #. Chapter name”. If we want to show only the chapter name, without the number, we need to redefine this command in the preamble by writing

\renewcommand{\chaptermark}[1]{ \markboth{#1}{}}

To get the section name without its number Headers and footers, and page styles 133

\renewcommand{\sectionmark}[1]{ \markright{#1}}

To make the chapter name appear in a particular font family, it is enough to enclose the \leftmark with the corresponding instruction. Following our example, it would be

\fancyhead[LO]{\nouppercase{\coral{\leftmark}}}

As always, the fancyhdr documentation provides (a lot of!) extra informa- tion, such as the right way to include a picture in our headers or footers.

12.4 Create and use page styles

From now, we will talk about how to define and use different page styles, solving some problems “not always desired features” presented in the de- fault options of most document classes. Everything will be done with pure LATEX code. Life is hard. Let’s suppose we need to create a document with headers and footers that present the following structure

1. Index with pages numbered with roman numerals

2. A non numbered “Chapter” with the foreword

3. First part

4. First numbered chapter

5. ...

We have talked about numbering the index pages in chapter 10, and we also introduced the tools to set-up headers and footers above. To obtain the Part and Chapter environments we need a “book” document class. A non numbered chapter can be introduced with the Chapter* (with the star) environment, so everything seems easy, right? The problem with all this, because without problems this section would not exists, have several parts. To begin with, the foreword created with the 134 Create and use page styles starred, unnumbered chapter will not be included in the index, and its head- ers will show “index” instead of the unnumbered chapter name. Both prob- lems have the same origin: the header will not change because the unnum- bered chapter, which is also an “unindexed” chapter, does not update the corresponding “mark” information. To solve this, we need to create a page style with the information we want in the foreword headers, and manually tell LATEX to add an index entry. To see how all this works, let’s look at a complete example in detail. In the LATEX preamble we have to write:

% The normal page style, with its headers \pagestyle{fancy} \fancypagestyle{normal}{% \fancyhead{} % clean the headers to % let place to what's next \fancyhead[RO,LE]{\thepage} \fancyhead[LO]{\nouppercase{\leftmark}} \fancyhead[RE]{\nouppercase{Our Great Book}} \fancyfoot{} } % The special page style \fancypagestyle{special}{% \fancyhead{} % clean the headers \fancyhead[RO,LE]{\thepage} \fancyhead[LO]{\nouppercase{Introduction}} \fancyhead[RE]{\nouppercase{Our Great Book}} \fancyfoot{} } % The index page style \fancypagestyle{index}{% \fancyhead{} % clean the headers \fancyhead[RO,LE]{\thepage} \fancyhead[LO]{\nouppercase{Index}} \fancyhead[RE]{\nouppercase{Index}} \fancyfoot{} } Headers and footers, and page styles 135

This code redefines the “normal” page style and also creates two new styles called “special” and “index” that we will use in the unnumbered chapter and the index, respectively. Now, at the point of the document where we want to have the TOC, we need to insert a “TEX box” and write on it

\frontmatter \setcounter{page}{1} \pagestyle{index}

(the second line is not really necessary). With this we are telling LATEX that what follows is the space devoted to the index and must have the page style we defined for it. If we want to insist on using uppercase Roman numerals (seriously, guys, from where did you get that weird thing about lowercase roman nu- merals?) we could add

\pagenumbering{Roman}

Just to be sure. Below that box, we need to go to Insert List/TOC Table of Contents and after that we need another TEX box with the code

\mainmatter \setcounter{page}{1}

(the second line here is not really necessary either). This code indicates that now begins “the real thing,” that we are in the main topic. At this point we insert the unnumbered chapter using the environment menu, and write the title, for example “Introduction.” Use the same title defined in the “special” page style!

On the line immediately below the title we need insert another TEX box with this content

\pagestyle{special} \addcontentsline{toc}{chapter}{Introduction} 136 First page of the chapter

The first line assigns the page style “special” to the content that follows, while the second line adds a line in the TOC pointing to that page, using the selected level (chapter) and the selected text (Introduction, maintain- ing consistency here is also important). Finished the introduction, it is time to move on. After applying (if we need it) the “Part” environment and then the “Chapter” environment (with- out the star), we need the last TEX box with the following code

\pagestyle{normal} so everything is back to “normality.” The rest of the document is normal, we do not need more TEX boxes. At least, not because of this problem. Some links: Create page styles in LATEX http://tex.stackexchange.com/questions/37574/ different-headers-for-different-chapters Add a non numbered chapter to the TOC: http://wiki.lyx.org/FAQ/TOC#addcontentsline

12.5 First page of the chapter

By default, in book document classes the first page of each chapter uses a style called “plain.” If we want a different style we have to add, to the LATEX preamble, something like the following code

\fancypagestyle{thefirst}{% \fancyhead{} \fancyhead[R]{\nouppercase{Our Great Book}} \fancyfoot[C]{Page \thepage} } \makeatletter \let\ps@plain\ps@thefirst \makeatother Headers and footers, and page styles 137

The first lines define a page style called “thefirst” while the last three (OK, the central one) change the “plain” page style for our “thefirst.” With this code, the first page of each chapter will show, to the right of the header, the text “Our Great Book” while at the footer center we will get the word “Page” followed by the page number.

12.6 Blank pages

If we create a “two-sided document” with one of the Book document classes, we will surely get several automatically inserted blank pages: chapters always start in a “right” (odd) page, so if the previous chapter ended in a odd page too, a blank page will be introduced to fill the gap. By default, for those blank pages LATEX uses the same page style used in the body of the chapter, so the blank page will not be really blank: it would have the same headers and footers of the rest of the chapter. To make those blank pages really “blank,” we can use the emptypage package. In TEX Live this package is called

texlive-emptypage

Once installed, in the LATEX preamble we need to add this line:

\usepackage{emptypage}

Now, what if we want a different, not fully blank page? For some legal documents it is necessary to add a text that says “this page was intentionally left blank” or something like that. Looking at the documentation for the emptypage package we can see that it only redefine the blank pages to make them use the page style called “empty,” so we only need to pick that example and write the following:

\fancypagestyle{rare}{% \fancyhead{} % \fancyhead[LE]{\thepage} \fancyhead[RE]{\nouppercase{Empty page}} \fancyfoot[CE]{Empty page} 138 The page style for the “Part” environment

} \def\emptypage@emptypage{% \hbox{}% \thispagestyle{rare}% \newpage% \if@twocolumn% \hbox{}% \newpage% \fi% } \def\cleardoublepage{% \clearpage% \if@twoside% \ifodd\c@page% \else% \emptypage@emptypage% \fi% \fi% }

I leave as homework the interpretation of this code and its possible mod- ification to adapt it to any circumstance.

12.7 The page style for the “Part” environment

In a previous section we have seen how to create and apply a new page style in a LATEX document, to change the header or footer content. Now we face a similar problem, but with a more complex solution: to change the page style associated with the Part environment. The Part environment, used to group chapters in “book” document classes, has a particular page style associated to it, and that page style could have, depending on the document class, a footer with the page number. Let’s suppose we want to eliminate that page number, could we use what we have learned above? Unfortunately, no. The problem with the Part environment is that it is also associated with page breaks, so any instruction like \thispagestyle used before or after Headers and footers, and page styles 139 this environment will be applied to the page before or after and not to the one we want. We cannot use the \thispagestyle inside the Part environ- ment either, because that instruction cannot be nested. Then? Well, we have to “patch” the Part environment. I have found the following code in this LATEX Community forum topic http://www.latex-community.org/forum/viewtopic.php?f=47&t=5809 Basically this code change the definition of the \part environment, assign- ing to it the page style “empty” that does not show headers or footers. The complexity of this code comes from the fact that it covers many pos- sible situation, such as the possibility of using a one or two-sided document, in one or multiple columns: that is why there are so many “if” commands. So, going to the LATEX preamble, we need to write the following:

% \part pages without footer \makeatletter \renewcommand\part{% \if@openright \cleardoublepage \else \clearpage \fi \thispagestyle{empty}% \if@twocolumn \onecolumn \@tempswatrue \else \@tempswafalse \fi \null\vfil \secdef\@part\@spart} \makeatother

Done. And yes, LATEX can be very strange. Note: There is a simpler way, but for some reason it does not always work. It is about patching the Part environment using the etoolbox command 140 The page style for the “Part” environment

\usepackage{etoolbox} \patchcmd{\part}{\thispagestyle{plain}}{ \thispagestyle{empty}} {}{\errmessage{Cannot patch! \string\part}}

But as I said: many times it does not work, so you will proba- bly get the error message defined in the last line. Oh, well.

Now, how can we change the page style that follows the Part environ- ment? After all, in this book you can find some inspired phrases there.

\makeatletter \def\@endpart{\vfil\newpage \if@twoside \if@openright \null \thispagestyle{empty}% \vspace*{3cm}% \begin{quote}% \partnote \end{quote}% \fi \fi \if@tempswa \twocolumn \fi} \newcommand\partnote{} \makeatother

Here we have several things. To begin with, we redefine the “endpart,” the end of the Part, then we define a new quotation environment, with everything and an initial space, and we assign a page style to all that. The curious reader will find how I have created the character style for that “phrase” in the appendix B. At this point, you should be able to under- stand all that code. Chapter 13 Drop Caps and similar topics

urely the reader has found documents that show the “special effect” presented in this particular paragraph: the first letter of the first word on the first line is spread over several lines, per-  haps showing (as here) a special and ornate font, with the rest of that first word written in small caps. This style is known as “Initial” or “Drop Caps.” To get this effect in LATEX/LYX we need to use the lettrine package.

13.1 Something traditional

n LYX we have support for this package and in section 6.3 of the user manual that can be found in Help Embedded Objects is clearly explained one way to use it. Because, as we will see soon, I there is another way, which is quite simple. The “official way” is incredible powerful, but implies the need to choose every detail every time we want to use the feature, what if we need to use several times in the document, always keeping the same formatting? We could use them, for example, in the first paragraph of each chapter. Let’s see how to make things more “autonomous.” After verifying that the package is already installed in our LATEX distribu- tion, we are ready to begin. The documentation for the Lettrine package is installed, in Linux, in

141 142 Something traditional

/usr/share/texmf/doc/latex/lettrine/lettrine.pdf /usr/share/texmf/doc/latex/lettrine/demo.pdf Now we have to go to Document Settings Modules (we talked about modules in the chapter 8) and enable the module called Initials. Click Apply, not in OK, we still have to work on that menu! Yes, as always, we have to go to the LATEX preamble to add some code. This document is configured to use XƎTEX with the EB Garamond font and defines an “alias” to a font called Pali,1 using the “stylistics alternates” (+salt). This is what I wrote in the preamble:

\newfontfamily{\Iniciales}[ RawFeature={+salt}]{Pali} \renewcommand{\LettrineFontHook}{\Iniciales} \setcounter{DefaultLines}{4}

The first instruction defines a new “font family” (we talked about that in section 6.2). That definition is used in the second instruction to indicate to the Lettrine package which is the font we want as Initial. The third instruction tells how many lines the Initial should take. It is possible to control the vertical positioning of the Initial character adding a fourth line

\renewcommand{\DefaultLraise}{0.35}

where the value “0.35” can be changed to anything we need. Generally, this is not necessary. Done all that, when we want to add a new Initial we select the first char- acter of the paragraph and we make a right click Text Style Initial . To get the rest of the word in small caps, we must enclose it in braces and put the result (rest of the word plus braces) in a TEX box (just select everything and press Ctrl L ). In the editing window it will be shown as you can see in figure 13.1, in the output... well, you have already seen it. The Lettrine documentation is short, so you will have no problems finding more options to adjust everything quickly and easily.

1. http://www.softerviews.org/Fonts.html#Pali Drop Caps and similar topics 143

Figure 13.1: Initials during document edition in LYX

13.2 Be careful with the number of lines!

recisely, we must to be careful! The number of lines in the paragraph that uses the Initial character is important, because if we use a four line Initial in a P two line paragraph the initial will crash with the following para- graph. Something that, clearly, is not happening here. What is the trick? Well, pretend to use two short paragraphs by building a long one with a line break in the middle of it. In LATEX, line breaks are inserted with a “\\” (without quotes), but in LYX it is much easier: we just have to press Ctrl . In the LYX window we will see an “angled arrow” in red. Being everything in the same paragraph, the nasty overlap is avoided, but the second “paragraph” does not show the first line indent. But we have indent here. Trick? Here we have a problem: the normal LATEX codes for in- serting horizontal spaces do not work at the beginning of a paragraph, then? Insert Formatting Phantom Horizontal Phantom and in the resulting box write, for example, a couple of “m.” Those “m” will be shown during edi- tion between angular brackets and crossed, but don’t worry: in the output we will only have the corresponding space. 144 A variant: a “raised” initial

13.3 A variant: a “raised” initial

ere the “trick” is a small variation of the previously shown code. H A In the LTEX preamble (of course, after enabling the Initials module and everything else) we need to write:

\newfontfamily{\Iniciales}[ Scale=2,RawFeature={+salt}]{Pali} \renewcommand{\LettrineFontHook}{\Iniciales} \setcounter{DefaultLines}{1}

As you can see, we are defining everything in almost the same way as before, but with an additional instruction that makes the font defined in the new font family \Iniciales to be displayed in double size (clearly, you can al- ways play with the Scale value) while the number of lines has been changed to 1. And that is enough so the Initial does not “go down,” but rather show itself, bigger, in the same line of the text.

13.4 A challenge

ight in this point I leave you with a small challenge: com- bine everything we have seen before to get an Initial that Rtakes several lines (let’s say, two), but “goes up” enough to show what you are seeing in this paragraph. C’mon, it’s easy! And no, you will not see the solution in the appendix with the LATEX preamble code for this document, because this initial was created “in place” using the Initial environment with custom instructions inserted just for this paragraph. You cannot cheat! Drop Caps and similar topics 145

13.5 An alternative: first line of paragraph in small caps

An alternative to the use of Initials/drop caps is to make the first line of the first paragraph be written in small caps, something that can be seen in some magazines (and in this paragraph, of course). The only way I have found to obtain this effect in an (almost) automatic way with LATEX is to use the magaz package. The documentation for this package is installed, in Linux and with TEXLive, in /usr/share/texmf/doc/latex/magaz/magaz.pdf However, this package it is a bit “capricious.” If you insert some math in the first line, make sure it is far from the right margin, otherwise you will get into trouble. Also, if you insert italics in that first line, make sure the font you use support small caps in it! Not all fonts offer small caps in their italic shape. Hyphenation can be a problem: sometimes a syllable may disappear, but do not ask me what triggers that. Last problem: you cannot get rid of the first line indent. At least, I found no way to do so. In its favor, we can say that is quite easy to use. In the LATEX preamble we write

\usepackage{magaz} and then, in the paragraph we want to modify, we open two “TEX boxes,” one at the beginning of the paragraph with the command

\FirstLine{ and the other at the end with a

} to close the instruction. The package automatically changes the format of the first line without any additional work. It is important to note that the command \FirstLine must be at the beginning of the paragraph, otherwise we will get an error. 146 An alternative: first line of paragraph in small caps

This package offers more options. For example, it is possible to select a different format for the font used in the first line with the instruction

\renewcommand\FirstLineFont{\ } but the brief documentation for this package is clear enough, so I will not go deeper into this topic. Chapter 14 Figures and other floats

We have introduced the concept of “floats” in subsection 4.1.7: an object within which we can put figures or tables and then let LATEX manage their positioning in the compiled document. In this chapter we will see some options for modifying the formatting of floats and their content.

14.1 Adjust the size of inserted images

When you insert an image in LYX, that image will be displayed in its actual size when the document is compiled, and that means that if the image is larger than the page, it will go through the margin. In fact, some images will demolish the margins. This problem can be solved in two ways, one manual and the other semiautomatic. Let’s see both methods.

14.1.1 Manual adjustment of image size Either when inserting a picture or later with a click on it, we obtain the menu that is shown in figure 14.1. As you can see, checking Scale graphics (%) allows us to reduce the image simply by writing the appropriate percentage. For example, entering “60%” we get a picture that is 60% of its actual size.

147 148 Adjust the size of inserted images

Figure 14.1: Manually modifying the width when inserting an image Figures and other floats 149

But, you may ask, how do we know what the appropriate percentage is? Well... trial and error, I guess. At the fourth or fifth attempt you will surely get it right. I know, I know, it is not practical. But don’t worry and read the next subsection that the solution to this is quite easy and “elegant.”

14.1.2 Automatically adjust the size

It is possible to ask LATEX to adjust by itself the image size as a function of the text area. For this, in the same menu that is shown above (but without activating the previous option!), we need to change to another tab, in ... Opciones de LaTeX/LyX (figure 14.2) If we want the picture to take exactly the 80% of the text area, in the field ... LaTeX options we need to write

width=0.8\textwidth

The instruction is quite easy to understand: the first half says “pick the 0.8 (80%) of the width” while the second half says “of the text area.” If we want the picture to take the 100% of the width, we can simply avoid the first half by writing:

\textwidth

It is important to keep in mind that this will force any image to take exactly the chosen percentage: larger pictures will be reduces, which if fine, but the smaller ones will be enlarged, which can be bad, so pay attention when using this option, to only apply it to pictures that really need it. To use the full page width instead of the text area, we can change the previous instruction by

\paperwidth

But, be aware of the margins... 150 Adjust the size of inserted images

Figure 14.2: Let LATEX do the dirty work Figures and other floats 151

14.1.3 Size of the image in the editing window As can also be seen in figure 14.2, it is also possible to select how the picture will be displayed (or if it should be displayed) in LYX during document edit- ing: while working it is not really necessary to see the picture at its highest resolution, so it might be a good idea to reduce it or even decide not to show it at all.

14.1.4 To avoid repetition: graphic groups But now, do we really have to do all that every time? No! As you can also see in figure 14.2, there is the option “Graphic group.” With this option, we can assign a name to a particular graphic configuration, so we can use it without effort in the next picture: with “Open new group” it is possible to assign a name to the particular configuration we want to save, while with the menu “Assignedto group” we can later apply that setting to any picture. Easier than that, impossible.

14.2 “Wrapped” figures

In this section we will talk about figures surrounded by text, like the one that you can see bellow in this section. But before continuing, I must admit that this is one of the few points that LATEX does not handle very well: wrapfig, the package we need to use here, can be quite “unstable” and provide unpredictable results. For exam- ple, with the default options, if when compiling the document the figure falls near the bottom margin it could “break” the page footer and even leave a gap on the next page (try it on a test document: it can be fun). The pic- ture may even disappear from the document without a single warning. The package does not verify if there is enough space to put the picture there. We will see how to fix that bellow. LYX offers full support for that package: we just have to go to Insert Float Figure wrap float (we can also insert tables from there). It is impor- tant to keep in mind that if we insert the wrap float between two paragraphs, 152 “Wrapped” figures the figure will be surrounded by the second one, while if we insert the wrap float between two words within the same paragraph, the figure will be sur- rounded by the lines of text that follow that point. This means that great care must be taken when placing the wrap floats. So, can we make them float the same way normal figures do? Sort of. How do we choose which side of the page is used, or the fraction of the page area it will take? That’s easier. With a right click on the wrap float label, we can access a config- Figure 14.3: A nice penguin I uration menu (figure 14.4). The adopted online (to the anonymous au- “placement” options are Outer (to thor of this and other penguins, thank the right on odd pages and to the you) left on even pages), Inner (the other way round), Left and Right. The option Allow floating is the one that correct the previously commented problem. Done? Well, not quite:

• Wrap floats cannot be used in combination with numbered or bul- leted lists.

• If the wrap float is in the last paragraph and the text is not enough to “surround” it, depending on how the flotation thing was set, we could have a float that goes after the text and does not respect the chosen side (with flotation) or a “half wrapped” float (without flota- tion).

• With two nearby wrap floats the result could be pretty bad (just try it!).

• Even if the numbering is integrated with the numbering of the nor- mal figures, we could obtain a wrong order: for example, the normal Figures and other floats 153

Figure 14.4: Setting up the “wrap float”

float numbered “5” at the beginning of the page and the wrap float with the number “4” bellow it. • ... So, yeah, this is a package that can provide some headaches, requiring a lot of manual control over the document before considering it “ready.” Now you know!

14.3 Center pictures or tables inside floats

If we have a picture inside a float that does not take the entire width of the page, either because it is small or because we changed its size to a percentage of the text area, it will end on the left when compiling the document. This can be a serious problem if, as we will see in the next section, we decided to center the caption. Is it possible to automatically center (by hand is always possible) the picture or the table inside our floats? The simplest way to obtain this effect is to redefine the macro that give format to the floats, writing the following in the LATEX preamble:

\makeatletter \g@addto@macro\@floatboxreset\centering \makeatother 154 Setting the caption text formatting for all floats

I have found this solution here: https://tex.stackexchange.com/questions/23078/how-can-i- automatically-center-an-image

14.4 Setting the caption text formatting for all floats

The easiest way to set up the captions in figures and tables in a LATEX docu- ment is to use the caption package. In Linux and with TEXLive (you need to install texlive-caption and texlive-caption-doc) you can find the documentation in /usr/share/texmf/doc/latex/caption/caption-eng.pdf The documentation is quite simple, so here I will just provide a quick example on how to use the different parameters that this package offers. The idea is to obtain captions that:

• are justified, but the the last line centered

• have a label formatted in Small Caps

• have the text set in italics

To get this, we have to go to the LATEX preamble and write

\usepackage{caption} \captionsetup{justification=centerlast,% labelfont=sc,textfont=it}

The first line declares the caption package, while the second line set it up with the three mentioned options. Other options offered by caption: change margins, the size or the fam- ily of the font used, line spacing, text color, modify or even eliminate the label name (to get only the number), insert a break between the label and the caption text, the distance between the picture and the caption (the skip option), etc.. It is interesting to note that the \captionsetup command can be used not only on the preamble: by inserting it in a particular float, we can set up that caption. Figures and other floats 155

There is one last “trick” related to the setting of floats: make the cap- tion appear on the side instead of above/bellow. But that trick will require working with custom modules and local layouts with great style, so we will leave it for the section 15.2.

14.5 Rename floats

LATEX offers by default two types of floats: Figure y Table.LYX adds a third: Algorithm. Now, can we change those names? Maybe we need to use Diagram instead of Figure or Script instead of Algorithm. Yes, of course we can! But keep in mind that changing the labels is not enough: we must also redefine the corresponding indexes to avoid confu- sion. We can use, in the LATEX preamble

\usepackage[english]{babel} \addto\captionsenglish{ \def\figurename{Diagram} \def\listfigurename{Index of diagrams} }

to change Figure by Diagram. If we want to change the name used by the table floats, we need to use \tablename{new-name} for the label, while for the index the command is \listtablename{Index of new-name(s)}. See here https://texfaq.org/FAQ-fixnam to get a list of names that can be changed with this method.

14.6 Change the numbering scheme of figures and ta- bles

That is easy! In fact, we did something similar in the chapter 11. To number “Figures” with Roman numerals (in uppercase!), we have to write in the LATEX preamble 156 Change the numbering scheme of figures and tables

\renewcommand{\thefigure}{\Roman{figure}}

For tables we only need to change both instances of figure by table. And to use alphabetical characters instead, well, you know: chapter 5. Chapter 15 Extras

In this chapter we will talk about some really particular details. The first topic will be how to describe menus and keyboard shortcuts. Next, we will discuss how to configure the captions of figures and tables so they appear to the sides instead of above or below. Talking about captions, we will discuss how to add a new type of float to our document using local layout and the photo package. We will briefly introduce the use of “colored boxes” in our documents. The chapter closes with a list of many interesting topics that were not addressed in the book.

15.1 Describe keys and menus: the menukeys package

Throughout this book, I introduced several keyboard shortcuts and menus, such as Ctrl or Document Settings LaTeX Preamble . There is no “official” way to do so, but a really simple “unofficial” one is the use of the menukeys package. I will briefly describe here how to use it. The menukeys manual is generally installed in /usr/share/texmf/doc/latex/menukeys/menukeys.pdf It is really complete, but it presupposes a minimum level of knowledge on the part of the reader, so even if all the options are clearly written, many times it is not clearly stated how to use them.

157 158 Describe keys and menus: the menukeys package

15.1.1 What is menukeys This package offers three “macros:” • A macro to show keyboard shortcuts as “keys” • A macro to show menus • A macro to show file paths The easiest way to use it is to enable the use of non-TEX fonts. I mean, it is possible to use this package with normal LATEX fonts by changing the file’s encoding... but let’s avoid that topic. In the LATEX preamble we have to write

\usepackage{menukeys} to activate the package... with its default settings, and that imply the use of Mac keys instead of PC keys. That means that keys like “Enter” or “Tab”will appear strange to many penguin users like me. To use the PC keys we need to pass a parameter to the package to say that we want to use the (ouch!) Windows keys, changing the previously shown instruction in the preamble to:

\usepackage[os=win]{menukeys}

This is the instruction I used in this document, but menukeys offers many key “formats” and presentations for menus to choose from. For ex- ample, if we want the keys to be shaded and round and the menus to be more rounded at the corners we need to add two lines to the previous code:

\usepackage[os=win]{menukeys} \renewmenumacro{\keys}{shadowedroundedkeys} \renewmenumacro{\menu}{roundedmenus}

The available styles are listed from page 6 of the package manual. It is important to keep in mind that hyphenation does not work on text that use these styles. Even if we have a long phrase as part of the menu path, that phrase will not break at the end of line, “breaking” the right margin. When using this package it is important to be careful with the output to avoid unpleasant surprises. Extras 159

15.1.2 Using menukeys in LYX The are two ways to use this package in LYX: a “brute force” method using a TEX box or a “local layout” (section 8.3). However, before presenting the second (more comfortable) method, we must know the first one: it is the only way to know the codes to use in the local layout. Well, in a TEX box, for a file path, we need to write:

\directory{/usr/share/texmf/doc/latex/ menukeys/menukeys.pdf}

while for menus we have two options, use the default separator:

\menu{Document > Settings > LaTeX Preamble}

or explicitly indicate each time which separator we want

\menu[,]{Document , Settings , LaTeX Preamble}

For a key:

\keys{\tab}

will give . In page 13 of the menukeys manual we can find a complete list with all available keys. It is important to keep in mind that if we write a key sequence without the slash, for example

\keys{Meta}

this sequence will be considered as a single key Meta . For more keys, more \keys commands or, if we want a separator, just one command with a “plus.” For example,

\keys{\ctrl}\keys{N}

will give us Ctrl N , while 160 Describe keys and menus: the menukeys package

\keys{\ctrl+N}

will give Ctrl + N . Now that we know how everything works, we need to go to Document Settings Local Layout and create a character style to apply the “menu for- matting:”

Format 66 InsetLayout Flex:MenuKeys LyxType charstyle LabelString menukey LatexType command LatexName menu Preamble \usepackage[os=win]{menukeys} EndPreamble ResetsFont true End

Now in our document we only have to write the menu path separating with a “>” each step, to then select everything and with a right click Text Style select “MenuKey.” Doing so, in the LYX editing window we will see text Document > Settings > LaTeX Preamble more text menukey but in the output text Document Settings LaTeX Preamble more text I leave as a homework for the reader to figure out how to create a local layout for keyboard shortcuts.1 And that is all about this topic on my part. The package offers many more options, including the ability to define your own styles, but I will not enter those details: with all what we have said, the package documentation should be clear now. That and the fact that I quite like the default options and I have no intention to change them. I mean, other than the Mac keys. Writing “win” in my documents... that was tough.

1. You can also cheat and see the appendixes, but that will be cheating. Extras 161

15.2 Side captions for figures/tables

We have already seen in section 8.1 how to add modules to LYX, now we will see how to use, and modify, one that is quite interesting: sidecap. This module (well, two modules) adds a new float that makes it possible to put captions on the side of figures and tables, instead of above or bellow. The sidecap module uses the LATEX package of the same name, inte- grating it into the LYX workflow. From this page: http://theorie.physik.uni-konstanz.de/jrioux/lyx/ it is possible to download the following files (we need to pick the LYX 2 versions!):

• sidecap.module: it is the main version. It creates floats whose num- bering integrates with normal floats and with a format that follows what we have established for them.

• sidecap-starred.module: as the previous one, but without num- bering.

Installing the module and reconfiguring LYX, now we have to go to Document Settings Modules to activate the Sidecap module. After that, we just have to go to Insert Float ... to insert the floats labeled as “side caption” we need. Now, by default the sidecap package places the captions in the “outer” part of the page (to the right on odd pages and to the left on even pages for “two-sided” documents) with the caption aligned to the lower part of the figure. Changing the latter is easy. If in the LATEX preamble we write

\sidecaptionvpos{figure}{c}

the caption will be vertically centered. Changing the c with a t the cap- tion will be top aligned. Changing figure for table we can set the vertical alignment of table captions. Unfortunately, changing the side of the caption is not so easy. If the default option is appropriate, this module is really useful, but if we need something else (for example, to have the caption in the inner part of the 162 Adding a new float page, or always to the left or to the right) we have to change the module. To do so, we can open it in a text editor, copy the content from “Format” to the end and paste it in a new “local layout” (section 8.3). Modifying the line

\usepackage{sidecap} to something like

\usepackage[innercaption]{sidecap}

(or leftcaption or rightcaption, whatever we need) we get the desired alignment. Now we just have to click on “convert to the new format” (the module is quite old), validate and accept the changes. Done! We have not only seen how to use an external module, but also how to convert it to a “local layout” and how to adapt it to fit our needs. Now it should be easy for the reader to take all this to learn how to build a new module! Not bad for an “extra” chapter!

15.3 Adding a new float

A completely unexplained example about how to add features to LYX: add a new float using the photo package. In the local layout, write

Format 66 AddToPreamble \usepackage[]{photo} \usepackage[english]{babel} \addto\captionsenglish{ \def\photoname{Photograph} \def\listphotoname{Index of Photographs} } EndPreamble Float Type photo GuiName "Photo" Extras 163

Placement tbp Extension loscf NumberWithin none Style plain ListCommand listofphotos ListName "Index of Photographs" RefPrefix Photo IsPredefined 1 UsesFloatPkg 0 End

Now go to Insert Float . Also check Insert List / TOC . Enjoy.

15.4 Colored boxes

Let’s suppose we need something like this in our document: This is the colored box title This is the content of the little colored box

That’s it, a “box” with colored borders, possibly with a title on top of it and with all the bells and whistles. For that and much more, there exists the LATEX package tcolorbox, and LYX offers graphical support for it. In Document Settings Modules we need to activate the module Fancy colored Boxes and we are ready to go to Insert Custom Insets (without the module, that menu would be empty) to pick one of the options. Color Box provides a box that takes the width of the text area, Fit Color Box provides a box that adapts to the content, etc. When choosing, for example, Color Box, we will find in the LYX editing window one of those insets like the one of the footnotes or the floats: a label on the left that indicates what type of “box” we are using and a space to the right where we can write. Writing some content and compiling the document we will find in the output a gray box without title, something a bit disappointing if you ask me. That is because we need to pass some parameters to obtain the needed effect. 164 Things I have not talked about

With the cursor within the box, going to Insert Color Box Options or through a right click Color Box Options we will get a box inside the box where we can write the necessary parameters. For example, to get the box opening this section I wrote

colback=red!5!white,colframe=red!75!black,title=This is the colored box title

What all that mean, you may ask? Well, the tcolorbox documentation, which in Linux can be found in /usr/share/texmf/doc/latex/tcolorbox/tcolorbox.pdf takes more than 150 pages, so it is completely beyond the scope of this brief section to talk about all the available options: macros to create indexes, the- orems... to see some examples of what this package is capable of, check the following document: /usr/share/texmf/doc/latex/tcolorbox/tcolorbox-example.pdf It is also possible to read the manual for this module that comes with LYX and can be found in Help Specific Manuals Colored boxes . Dear reader, now you know that the tool exists.

15.5 Things I have not talked about

LYX offers a huge arrange of possibilities to take advantage of the immeasur- able list of LATEX abilities. In this section I am going to briefly discuss some of those topics that were not covered in this book.

15.5.1 BibLATEX support

As we discussed in section 4.3, since 2.3 LYX offers support for BibLATEX. This is a topic of interest mainly for academics and requires some work to understand how it works. You know, the package documentation and internet are your friends. Extras 165

15.5.2 Presenting code with listings

LYX offers support for the listings package, which gives us the ability to format the code we write in our documents. With Insert Program Listings we obtain a box in which we can write any code, and with a right click in the box we can quickly choose the pro- gramming language, its “dialect,” the typeface, the length of the tabs, etc.. In this menu we can also pass parameters to the package to give color to the instructions and everything else. In chapter 8 of the manual you find in Help Embedded Objects there is more information.

15.5.3 PDF forms

After all, you can also use LYX to create “for the office” documents. In Help Specific Manuals PDF forms you can find a detailed description of this tool.

15.5.4 Sweave and knitr In Help Specific Manuals Sweave / Knitr you can find two brief manuals that explain how to use these interesting LATEX packages, which connect LYX with the statistical program R.

15.5.5 Computer Algebra Systems

If we make a right click inside the equation editor in LYX, we find the op- tion of “use computer algebra system,” and within this, several options like Octave, , etc.. This options can be used to quickly evaluate the in- 2 푏 2 serted expression. For example, selecting Maxima in ∫푎 푥 푑푥 we will get 푏 2 푏3 푎3 ∫푎 푥 푑푥 = 3 − 3 .

15.5.6 And much, much more I had better stop here, that adding a list of things that I have not talked about would also imply extending too much.

2. Of course, we need Maxima to be installed in the system! 166 Things I have not talked about

Create Feynman diagrams, write musical scores with LilyPond, linguis- tics, Beamer presentations, the Xy-pic3 package to create any kind of graph- ics from within LATEX, even writing in Braille find direct support in the graph- ical interface of LYX. And if you believe, dear reader, that what we have presented in this third part of the book has been a blow of LATEX code, let me tell you that we have not even scratched the surface of what can be done: things like gener- ating paragraphs with arbitrary shapes or even the use of LATEX to perform mathematical calculations is within the reach of the enthusiast “program- mer.” Do not forget that TEX is a Turing complete programming language! No one has said that all those things are easy and in the vast majority of cases they are not even worth the extra work. For example, controlling the shapes of the paragraphs involves a lot of manual work, but it is certainly possible. My intention with this book was to open a road. It is up to you to decide how far you want to go. As they say, happy LYXing!

3. https://ctan.org/pkg/xypic Part IV

Appendixes Where several details about the format of this book are presented

The grown-ups are very strange Appendix A All about typeface

To choose the right typeface for a text is one of those topics in which you will get more answers than people answering. This is not a book about design, but an explanation about how to use LYX to design. I do not have a background, therefore, I am not qualified to provide advice. But I can, of course, tell you what I use.

A.1 Fonts used in this book

As already mentioned, the body text font used is EB Garamond: http://www.georgduffner.at/ebgaramond/index.html Splendid recreation of ’s designs of the mid XVI cen- tury, this font has the enormous advantage (at least, to my eyes) of its beauty and the small disadvantage of not having a bold version (it is being devel- oped). Instead of bold, I used Small Caps, I think with good results. I also used the “character variation 11” with the OpenTypeoption +cv11. This option changes the shape of the number 1 when using old style numerals. For headings, I have also used a Garalde, Cormorant: https://github.com/CatharsisFonts/Cormorant This font is too detailed and with a too high contrast to be used as the main font, but in large sizes it is just perfect. Combining typefaces is a difficult art. While some projects make things (relatively) easy by providing “families” of fonts (Libertinus, Source pro,

169 170 More about typefaces

PT, Alegreya, etc.), which “sans” can we use that match a Garalde? From the people who created Cormorant we have an interesting proposal: Eau de Garamond https://github.com/CatharsisFonts/EauDeGaramond/ This font is in its early development stage, but I had no problems using it in this text. I did not find a designed to go side by side with a Garalde, so in the end I decided to opt for a classic like DejaVu Sans Mono: https://dejavu-fonts.github.io/ For the mathematical formulae I used a new project called Garamond- Math. I have talked about that font in chapter 6. In the examples used throughout this book, several other fonts where used.

A.2 More about typefaces

For more information about typefaces with free licenses, including the (more or less) detailed analysis of their advanced features, you can check my per- sonal blog: https://frommindtotype.wordpress.com/ selecting the “Font Review” category. In particular, I want to highlight a series of four articles called “typo- graphical concepts,” the first of which can be found here: https://frommindtotype.wordpress.com/ 2017/11/13/typographical-concepts-part-1/ Appendix B Local Layout

To develop this text, I have created several character styles to simplify the writing process. Below, the content of Document Settings Local Layout . But first, a few considerations. First of all, it is important to bear in mind that some styles defined here depend on instructions already present in the preamble, which will be pre- sented in the appendix C. And of course, in a “normal” document it is not necessary to define that many styles: the characteristics of this document makes such a list necessary. In fact, I think the style “textfrac” was used only twice... or once? Dammit! Always keep your styles under control! Formatting can help us express our ideas, but only up to a point: if the document presentation becomes too fancy, the reader will be distracted from the content. It is true that going too far with minimalism can result in a not so clear presentation, but we must not forget that “Complexity” is not a synony- mous with “Elegance.” After making these points, from next page you will find the “local lay- out” used in this document.

171 172

Format 66 InsetLayout Flex:HistoLig LyxType charstyle LabelString histolig LatexType command LatexName histolig Preamble \newcommand*{\histolig}[1]{{ \addfontfeature{% Ligatures=Historic} #1}} EndPreamble ResetsFont true End InsetLayout Flex:TextFrac LyxType charstyle LabelString textfrac LatexType command LatexName textfrac Preamble \newcommand*{\textfrac}[1]{{ \addfontfeature{% RawFeature={+frac}} #1}} EndPreamble ResetsFont true End InsetLayout Flex:Kleymissky LyxType charstyle LabelString kley LatexType command LatexName kley Preamble \newfontfamily{\kleym}[]{Kleymissky} \newcommand*{\kley}[1]{{\kleym #1}} EndPreamble ResetsFont true Local Layout 173

End InsetLayout Flex:MenuKeys LyxType charstyle LabelString menukey LatexType command LatexName menu ResetsFont true End InsetLayout Flex:KeysKeys LyxType charstyle LabelString okey LatexType command LatexName keys ResetsFont true End InsetLayout Flex:sinserif LyxType charstyle LabelString sinserif LatexType command LatexName sinserif Preamble \newcommand*{\sinserif}[1]{{\sffamily #1}} EndPreamble Font Family sans EndFont ResetsFont true End InsetLayout Flex:ttmono LyxType charstyle LabelString ttmono LatexType command LatexName ttmono Preamble \newcommand*{\ttmono}[1]{{\ttfamily #1}} 174

EndPreamble Font Family Typewriter EndFont ResetsFont true End InsetLayout Flex:LogoTipo LyxType charstyle LabelString HoLogo LatexType command LatexName loguito Preamble \newcommand*{\loguito}[1]{{\hologo{#1}}} EndPreamble ResetsFont true End InsetLayout Flex:PartNote LyxType charstyle LabelString PartNote LatexType command LatexName notitas Preamble \newcommand*{\notitas}[1]{{ \partnote\itshape #1}} EndPreamble ResetsFont true End Appendix C LATEX preamble

Bellow you will find what I have wrote in the preamble of this document. In the first lines I define the main font for the text, so I can use a particular OpenType feature. That was commented on the appendix A. This means that I have left as “predefined” the corresponding option in the document settings, do not forget that! Also, do not forget I have chosen the “Non- TeX Fonts Default” to choose which math font is used and that, also there, I activated “Enable micro-typographic extensions.”

\setmainfont{EB Garamond}[ Mapping=tex-text, RawFeature={+cv11}] % shape of the 1

\setmathfont{Garamond-Math}

\usepackage{hologo} % XeTeX & co. logos \usepackage[os=win]{menukeys} % keys and menus \newfontfamily{\voll}[]{Vollkorn} % for some examples

% for the initials chapter -- \newfontfamily{\Iniciales}[RawFeature={+salt}]{Pali} \renewcommand{\LettrineFontHook}{\Iniciales} \setcounter{DefaultLines}{4}

175 176

\usepackage{magaz}

% captions ------\usepackage{caption} \captionsetup{justification=centerlast,% labelfont=sc,textfont=it} % lo siguiente centra la imagen en el flotante \makeatletter \g@addto@macro\@floatboxreset\centering \makeatother

% all about page styles ------\renewcommand{\headrulewidth}{0.4pt} \usepackage{emptypage} % to make empty pages % really empty

% not show the chapter number % nor section in headers ------\renewcommand{\chaptermark}[1]{ \markboth{#1}{}} \renewcommand{\sectionmark}[1]{ \markright{#1}}

% the normal page style, with its headers \pagestyle{fancy} \fancypagestyle{normal}{% \fancyhead{} \fancyhead[RO,LE]{\thepage} \fancyhead[LO]{\nouppercase{\leftmark}} \fancyhead[RE]{\nouppercase{\rightmark}} \fancyfoot{} } % the special page style \fancypagestyle{especial}{% \fancyhead{} LATEX preamble 177

\fancyhead[RO,LE]{\thepage} \fancyhead[LO]{\nouppercase{Introduction}} \fancyhead[RE]{\nouppercase{Introduction}} \fancyfoot{} } % the index page style \fancypagestyle{index}{% \fancyhead{} \fancyhead[RO,LE]{\thepage} \fancyhead[LO]{\nouppercase{Index}} \fancyhead[RE]{\nouppercase{Index}} \fancyfoot{} } % the section about footnotes --- \makeatletter \renewcommand\@makefntext[1]{% \noindent\makebox[0pt][r]{% \@thefnmark.\space}#1} \makeatother % the section about headings ------\usepackage{titlesec} \newfontfamily{\cormorant}{Cormorant} \titleformat{\part}[display] {\huge\cormorant}{\filright%\thepart\ }{20pt}{\Huge} \titleformat{\chapter}[frame] {\LARGE\cormorant}{\filright \chaptertitlename\ \thechapter}{20pt}{\huge} \titleformat*{\section}{\Large\bfseries\cormorant} \titleformat*{\subsection}{\large\bfseries\cormorant}

% to make \part pages without footer \makeatletter \renewcommand\part{% 178

\if@openright \cleardoublepage \else \clearpage \fi \thispagestyle{empty}% \if@twocolumn \onecolumn \@tempswatrue \else \@tempswafalse \fi \null\vfil \secdef\@part\@spart} \makeatother \makeatletter \def\@endpart{\vfil\newpage \if@twoside \if@openright \null \thispagestyle{empty}% \vspace*{3cm}% \begin{quote}% \partnote \end{quote}% \fi \fi \if@tempswa \twocolumn \fi} \newcommand\partnote{} \makeatother Appendix D Other formats... and a greeting

A small list of other settings I have used.

D.1 Other formats used in this book

For this book I have activated the following modules: • Fancy Colored Boxes • Initials • Customizable Lists (enumitem) The page layout uses an A5 page with fancy headers and a “two-sided” layout. Margins are Top 2,5 cm Bottom 1,5 cm Inner 2,5 cm Outer 1,5 cm

I have activated the Hyperref support, allowing the links to break at the end of the line. I have removed the frames around the links and selected to color links with

179 180 And yes, direct formatting

linkcolor=cyan,urlcolor=blue

In the Bookmars tab I have selected “Numbered bookmarks,” so the PDF index also show the numbering. Output Format PDF (XeTeX)... I have already said everything else.

D.2 And yes, direct formatting

But only on one page! I am referring, of course, to the cover page: defining a style that will be used only there does not make sense, so I performed a few right clicks to change the paragraph formatting (right alignment) and the text formatting (its size), together with a few page breaks ( Insert Formatting ). The text with the font Kleymissky uses a style... with a manually modified size. What took more time was to put the image in its place. The penguin silhouette in front of the doors of Moria LYX was created in LibreOffice Draw over the profile of certain image that I used as an exam- ple in chapter 14, adding screenshots showing the program and the result of its use. As Draw does not allow exporting a “selection” when creating a PDF, the “slide” of the document was modified to have no margins and present the exact size needed for the picture. It is important, when exporting to PDF from Draw, to select “loose less compression” to not ruin the image... but OK, I am digressing, after all this is a book about LYX. From the Draw document I created a PDF file that was inserted in the page dedicated to the cover of this document. And here comes the interesting part. Creating a page style with its mar- gins only for the cover does not make sense, but if I only use the text area size, the resulting image would be too small, so the \paperwidth option (also commented in chapter 14) “sounds as a solution,” right? Not quite: making the picture start before the left margin needs some extra work. But everything can be solved! Here the sequence of commands used: First, a TEX box with Other formats... and a greeting 181

\begingroup \leftskip=-3em

The second instruction gives to the following paragraph a negative indent of 3 ... and to the next one, and the one that follows until the end of the document: that is why I have created a “group” with the first instruction, to isolate the effects of the \leftskip from the rest of the document. Below that TEX box I inserted the PDF picture commented before, set- ting its “LATEX options” with

width=0.81\paperwidth so it takes the 81 % of the full page width. Finally, after the image another TEX box with

\endgroup was used to close the group and finish the process. For the back cover, I used some vertical spaces from Insert Formatting Vertical Space , but they are easy to understand. So yes, I had to compile the document several times before everything was right. Oh, well.

D.3 Final greetings

If you got here, dear reader, thank you for your patience! I hope you enjoyed the book. I certainly enjoyed writing it. Trying to explain is that I have learned more than I thought I would come to know. The moment in which I decided to write this book now joins the moment in which you fulfilled your purpose of reading it to the end. The trip has been long, but I think it was worth it. Until the next Typographic Adventure!