# LaTeX - A document preparation system

## Underfull \hbox (badness 10000) in paragraph at lines x--y

Underfull \hbox (badness 10000) in paragraph at lines x--y
[] [] [] [] [] []						this must mean something too, but what ?
• 99 times out of 100 it means you have \\ incorrectly placed at the end of a paragraph. (source)
• An underfull hbox means LaTeX couldn't space the line wide enough to fill the entire width of the page, without increasing word spacing beyond the allowed maximum; the opposite is an overfull hbox, where a line couldn't be broken and extends past the edge of the printable area. Usually it happens if you forced a linebreak yourself (with \\), so if you avoid doing that this should be pretty rare (other causes are weird tabular environments or forced blank lines). (source)
• Find files + lines having those BAD \\ :
grep -En '^[[:blank:]]*[^%].*\\\\' *tex *cls

## Overfull \hbox (11.24971pt too wide) in paragraph at lines x--y

### Situation

Compilation of LaTeX documents very often outputs errors such as :
Overfull \hbox (11.24971pt too wide) in paragraph at lines x--y
[]\TU/Lato(0)/m/n/10 Lorem ipsum dolor sit amet, \TU/lmtt/m/n/10 consectetur adipiscin
g elit
These are only warnings (i.e. you may just ignore them), until the day something breaks ...

### Details

This is caused by a series of events :
• LaTeX works by creating "boxes" holding text blocks and does its best to make the text fit its box (letter / word spacing, hyphenation, ...). When this is not possible, a warning occurs.
• LaTeX may have difficulties fitting text into a box because it doesn't know how to hyphenate words (source)
• By default, TeX will never hyphenate what's in typewriter type. This includes text formatted with \texttt{}

### Solution

None of these solutions is perfect : you'll have to reach a trade-off between the time spent to fix / hack and the visual result (hint : the quicker the less efficient )
• stop using \texttt{} on the line causing the warning
• suggest possible hyphenations with \- so that LaTeX can pick the best solution (source) :
Lorem ipsum dolor sit amet, \texttt{con\-sec\-te\-tur a\-di\-pis\-cing elit}
• don't use a typewriter font at all and specify a different font instead (this is the hardcore solution !)

### Specify a different font

You probably have a macro like :
\newcommand{\myBeautifulMacro}[1]	{\texttt{#1}}
which is causing all this trouble. What you'll basically have to do is to turn it into :
\newcommand{\myBeautifulMacro}[1]	{{\fontfamily{lmss}\selectfont #1}}
• \fontfamily{fontSpec}\selectfont is how you select the fontSpec font
• the extra surrounding braces {} are there to limit the scope of the font change (i.e. make this an "inline" style, for those who are familiar with CSS). This is a common LaTeX hack.
• the hard (HARD !) part is to find the fontSpec value (here lmss)

#### Finding the fontSpec value (source) :

Sorry, this is still pretty mysterious to me. Unsorted notes below...
The LaTeX Font Catalogue :	http://www.tug.dk/FontCatalogue/

https://tex.stackexchange.com/questions/2305/what-fonts-are-installed-on-my-box
updmap-sys --listmaps | less

'fc-list' : list available fonts
fc-list | cut -d\ -f2-99 | cut -d: -f1 | sort -u
fc-query /usr/share/texmf/fonts/opentype/public/lm-math/latinmodern-math.otf

https://tex.stackexchange.com/questions/25249/how-do-i-use-a-particular-font-for-a-small-section-of-text-in-my-document
find /usr/share/ -type f -a -name "*sty" -exec grep -lE 'renewcommand.*sfdefault' {} \;
find /usr/share/ -type f -a -name "*sty" | xargs -I truc bash -c 'grep -E "renewcommand.*sfdefault" truc && echo truc' > result.txt

lmtt	Latin Modern Typewriter	==> no error, but I'm actually trying to avoid typewriter fonts
lmr	Latin Modern		==> works but doesn't match with other fonts (serif / sans serif ?)
lmssq				==> fine but too big
lmss

Fonts 3-letter codes : https://www.overleaf.com/learn/latex/Font_typefaces#Reference_guide

https://tex.stackexchange.com/questions/44361/how-to-automatically-hyphenate-within-texttt


## How to type special / accented letters in LaTeX ?

1. save / convert your document.tex as UTF-8
2. add to the document preamble :
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
3. enjoy typing characters normally

### Alternate solution

Type the special characters :
To display... Type
\ $\backslash$
| $|$
° $^{\circ}$
ç \c c
œ (like in "œuvre") \oe
&, $, #, _, % \&, \$, \#, \_, \%
é \'e
è, à, ù \e, \a, \u
â \^a
ï \"i

## LaTeX errors

Here are some common errors I encountered with LaTeX and Beamer, and their solutions :
Package babel Error: Unknown option frenchb'. Either you misspelled it (babel) or the language definition file frenchb.ldf was not found.
apt-get install texlive-lang-french
LaTeX Error: File mdframed.sty' not found.
apt-get install etoolbox
File ended while scanning use of \next
2 things to do (source) :
1. \end{frame} can NOT be indented
2. \end{frame} cannot have any comments directly after it

## pdflatex

pdflatex actually is :

ll /usr/bin/pdflatex
lrwxrwxrwx 1 root root 6 Nov	3 03:50 /usr/bin/pdflatex -> pdftex*

And where does it come from ?

dpkg -S /usr/bin/pdftex
texlive-binaries: /usr/bin/pdftex

## LATEX

apt-get install texlive-base texlive-lang-french texlive-latex-base

### Files of any LATEX report:

1. While working with LATEX, you will produce a text file document.tex
2. Then, you have to "compile" it :
latex document.tex
This outputs document.dvi (DVI = DeVice Independant)
3. This .dvi file can be :
• viewed as is : xdvi document.dvi
• or converted to PDF : dvipdf document.dvi and viewed with GhostView: gv document.pdf

### Tips for fancy headers :

Headers and footers have left and right sides, which content can be explicitly specified :

Descriptors value must be chosen from :

• L : left
• C : center
• R : right
• E : apply to even pages
• O : apply to odd pages

examples (source) :

\fancyhead[RO,LE]{\title}
\fancyfoot[C]{- \thepage{} -}

### How to generate nice pdf files from LATEX documents ?

When you make pdf files from LATEX with dvipdf or pdflatex, the fonts are very ugly to look at on the screen. This _may be_ because the standard LATEX fonts are not supported by Acrobat reader.
Solutions :

1. using the times font :
As a non-LATEX expert, I just want my PDF files to look nice, so let's go for the easy solution: include the times package in the header of the LATEX file : \usepackage{times}
2. OR : Using fontenc and dvips+ps2pdf, or dvipdfm :
I don't want the times font, I want to use the standard LATEX font. (Full technical details here !). So the header of my .tex file may look like :
\usepackage[T1]{fontenc}
\usepackage{ae}
When I have made my .dvi file, I write :
dvips -Ppdf -o outfile.ps myDviFile.dvi
Afterwards when I make the pdf with :
ps2pdf outfile.ps
Everything looks fine.
Instead of dvips, you can also go directly with dvipdfm (must be downloaded and installed), and specify the resolution and paper format :
dvipdfm -p a4 -r 600 -o report.pdf myDviFile.dvi
You can find lots of comments and solutions to he problem if you search Google with e.g: ae package fontenc T1 EC pdf.

### How to create an Introduction chapter without numbering ?

Just declare it this way :
\chapter*{chapter_name}

### Playing with colors (source, example : colors.tex) :

1. use the color package with the nodvipsnames option (disables the named model for dvips, to save memory) :
\usepackage[nodvipsnames]{color}
2. define your own colors with :
\definecolor{colorName}{rgb}{rr,gg,bb}
Other models than rgb are available, such as cmyk
• \pagecolor{colorName}: to change the page background color.
• \color{colorName}: toggles the current text color.
• \normalcolor: switches to the color that was active at the end of the preamble. Thus placing a \color command in the preamble can change the standard color for the whole document.
• \textcolor{colorName}{Lorem ipsum dolor sit amet}: writes "Lorem ipsum dolor sit amet" in the specified color
• \colorbox{background_color}{Lorem ipsum dolor sit amet}: writes "Lorem ipsum dolor sit amet" with a background color
• \fcolorbox{frame_color}{background_color}{Lorem ipsum dolor sit amet}: writes "Lorem ipsum dolor sit amet" with a background and a frame
xdvi can only render monochrome. Transform your document into PDF format to see the colors.

### Using hyperlinks in PDF documents

1. Load the hyperref package with its set of arguments (syntax : \usepackage[options]{packageName}):
\usepackage[
pdfauthor={John Doe},
pdftitle={The title of the document},
pdfsubject={The subject of the document},
pdfkeywords={document,keywords,separated,by,coma}
]{hyperref}
• To an external target :
• \href{target}{text}
• \url{url}
• To an internal target :
• Link : \hyperlink{targetName}{text}
• Target : \hypertarget{targetName}{text}
3. #### Notes

• The font looks better with pdflatex than with dvipdf but images are gone
• Hyperlinks work just fine while reading the PDF as "embedded" in a browser, but nothing happens if they're opened straight from Acrobat Reader
The \input command causes the indicated file to be read and processed, exactly as if its contents had been inserted in the current file at that point. The file name may be a complete file name with extension or just a first name, in which case the file file.tex' is used. (???)