Introduction

Hey, it’s great to see you again! In our last lesson, we downloaded an installed a LaTeX compiler and user interface program called MiKTeX. We then quickly looked around the all-knowing interwebs and found a LaTeX template for a book titled “Legrand Orange Book”. Using this template, we created our first PDF!

While this was a great first step, it leaves a lot to be desired. For all it offers, the Legrand Orange Book (LOB) remains stock and unbecoming of our personality. It’s time to change things up! Now, where to start…

One quick look at the online LOB template shows us that our fonts within the book are going to be non-uniform. If you’re anything like me, this is bothersome. Although there are a number of options as to where we should look to for the font option (is it in the TeX Document file (`.tex`)? Or maybe in the LaTeX Class file (`.cls`)?), the actual solution is a bit less obvious. If we do look in the `.cls` file, we can scroll down to the section titled “FONTS” — this seems like a sensical place to put a font setting.

```%----------------------------------------------------------------------------------------
%	FONTS
%----------------------------------------------------------------------------------------

\usepackage[utf8]{inputenc} % Required for inputting international characters
\usepackage[T1]{fontenc} % Output font encoding for international characters

\usepackage{avant} % Use the Avantgarde font for headings

\usepackage{mathptmx} % Use the Adobe Times Roman as the default text font together with math symbols from the Sym­bol, Chancery and Com­puter Modern fonts

\usepackage{microtype} % Improve typography
```

Although it’s tempting to change the setting for `\usepackage{avant}`, this is actually incorrect — but it does tell us that the headings use the Avantgarde font, while the other text in the book is Computer Modern Roman (which looks quite a bit like Times New Roman). The proper way to force all text (including headers!) in the book is to add the following command to the `.tex` document, after the `\documentclass` command as follows:

```\documentclass[
11pt, 			% Default font size, select one of 10pt, 11pt or 12pt
fleqn, 			% Left align equations
a4paper, 			% Paper size, use either 'a4paper' for A4 size or 'letterpaper' for US letter size
oneside, 			% Uncomment for oneside mode; this doesn't start new chapters and parts on odd pages; more suitable if book is to be read on screen and NOT printed
]{LegrandOrangeBook}

\renewcommand{\sfdefault}{\rmdefault}
```

Great! …so…what does it do, and why does it work? It turns out $LaTeX$ won’t let you create a new command if the same command already exists; that is, it won’t let you overwrite an existing command. However, this is precisely what the `\renewcommand` does. Explicitly stated, it lets us redefine a command instead of creating a new command.


If we decide to change back to the original LOB format in the future, we can always comment out this line. A quick comparison of the two situations is shown below:

Updating the cover image

With consistency restored to our textbook font, we now want to change the cover image to better match the personality of our textbook. Luckily, images are considerably more simple to change and their tags correspond to the point where the change needs to be made!

If we look in the LOB TeX Document file (“main.tex”), line 67 defines all of our variables for the title page. Within the \titlepage section, we see that the image of the title page is actually defined by another file in our book’s folder, “background.pdf”. If we poke around in the folder containing our $LaTeX$ files, background.pdf is located in the Image folder.

Let’s update this file. To find a new image, I directed my web browser to a free image website, Freepik.com, and filtered for License -> Free and Orientation -> Vertical. With these search parameters, this beautiful image came up, posted curtesy of user onlyyouqj. Remembering that we will need to attribute the image to its creator (unless you have a Premium membership), I download the image and located it in my Downloads folder.

From here, I double-click to open the file and locate the Print option in my photo viewing software. From here, I want to be sure to print (or save) the image to PDF with the same page type as our book. We can find this information back in `main.tex` on line 39, where the `\documentclass` defines our page type as “a4”.

Once I save (or print) the file in a4 paper size, I’ll save the resulting PDF as “newbackground.pdf” to the same folder as the original background.pdf file (for me, this is Desktop > book > Image > newbackground.pdf). Now, I can return to `main.tex` and change “background.pdf” (on line 71) to “newbackground.pdf”, and re-compile our $LaTeX$ book! This produces the following results; for comparison, I’ve included both the old cover (left) and new cover (right):

Updating chapter images

Fantastic, this book feels better already! Now what if we wanted to make the images of the heading sections also fluid-related? For this, I went back to Freepik.com, this time doing a search for free images with horizontal orientation, with the search term “fluid”. Immediately, I find this gorgeous image by user garykillian. Similar to our last image, I download the image (remembering I need to attribute it in my book!). This time, instead of saving the file as a PDF, I’ll rename the file “fluid_1.jpg”, and save it into the same folder where I saved my cover PDF.

With my new section image in hand, I return to main.tex, but this time I’m looking for $LaTeX$ code that defines a specific image. I find the following code snippet, which defines the image used in at the start of each new chapter

```\chapterimage{orange2.jpg} % Chapter heading image
```

Notice that the image doesn’t need the full file extension (C:\Desktop\book\Images), but only needs the filename. Since I’ve placed my newly acquired image (fluid_1.jpg) in the same Images folder, I only need to copy this command and move it to the line right before the section I want to define the image for!

For instance, the first location in our book with a section image is the Table of Contents. In `main.tex`, this is defined on line 105 (`\tableofcontents % Output the table of contents`). If we insert the above \chapterimage command on line 104, we can change the filename (orange2.jpg) to our most recent file (fluid_1.jpg), then simply re-compile the $LaTeX$ file! When the compilation completes, we see that our new image has replaced the older image! A comparison of the two is shown below:

Immediately, we notice that the two images have different sizes. Furthermore, the increased height of the new image dramatically takes away from the aesthetics since the bottom of the image now collides with the “Part One Title” box. We can easily fix this by cropping our new image to the same dimensions of the old image, resaving the image, and re-compiling the $LaTeX$ file. I used PowerPoint to accomplish this task, only taking a couple minutes. After resizing the new image, we get the following output. Although there is a slight vertical offset, we can again fix this via cropping and re-saving.

We can keep using this technique of downloading an image, renaming and saving the image, adding an image attribution, and copy/pasting the `\chapterimage` command anywhere there is a new section or chapter (ex. line 106 before Table of Figures, line 130 before the chapter “Sectioning Examples”, etc.)

Conclusion

In this tutorial, we spent some time modifying the default Legrand Orange Book (LOB) $LaTeX$ template to make it more of our own. Specifically, we altered the text commands to make the font throughout the book more uniform, and we updated the images of the book’s cover and the Table of Contents section. Now that our book has a personality better suited to our writing topic, we still need to fill in the text of the book to bring it to life!

In our next tutorial, we’ll set the book aside for a moment and take a look at another skillset: building a presentation in $LaTeX$. Knowing how to edit both types of documents will be very empowering, since we can now make documents of any type! For now, though, I hope this has been helpful in making your book feel less generic, and more like your creation! As usual, I appreciate you dropping by! Feel free to visit my full list of articles, visit my homepage, or sign up for automatic updates! See you next time.

Get new content delivered directly to your inbox.