# Automatically break line if it spans over x centimetres

I am using IguanaTex to insert latex text and equations to PowerPoint presentation.

This plug-in uses a default template to generate latex images (it compiles it to pdf then to image).

Here's an example of an output:

And here's the input that produces the above:

\documentclass{article}
\usepackage{amsmath}
\usepackage[parfill]{parskip}
\pagestyle{empty}
\usepackage{xcolor}
\usepackage{color}
\definecolor{mywhite}{rgb}{1,1,1}
\definecolor{myblue}{RGB}{153,255,255}
\color{mywhite}

\begin{document}

\begin{itemize}
\item
A compression technique used to reduce the bits needed\\
to encode symbols (e.g. letters).
\item
Based on the frequency of occurrence of a symbol in the data.
\item
Huffman code is optimal.
\begin{itemize}
\item To use our definitions and notations, given a text\\
containing $n$ different letters where $w_i$ is the frequency\\
of the $i$’th letter, Huffman Algorithm constructs\\
an Extended Binary Tree while minimizing $\sum_{i=1}^n w_il_i$.
\end{itemize}
\end{itemize}

\end{document}


Notice how I must break the lines manually by adding \\ wherever I find fit. This is really annoying and time consuming. I would love to make it automatically somehow.

In other words, what I'm asking is:
I want the line to automatically break whenever adding a word to it makes it span over more than x centimetres. Is that possible?

• Set the textwidth accordingly using package geometryor put the stuff inside a parbox. – Johannes_B Nov 7 '15 at 8:48
• Would you mind writing that as an answer and add an example? I'd really appreciate that. – so.very.tired Nov 7 '15 at 9:24
• Sorry, but presentations require manual breaking. Each slide should be looked at in order to find the best page breaks and no automated system will be able to do that: it's the same as breaking equations across lines, where the right place where to split depends on subtle semantic aspects. – egreg Nov 7 '15 at 9:50
• @egreg thanks for the tip. Actually, that's exactly what I'm doing: some of the slides have lines that I manually broke, but most of them are just text and it is easier that way. That's why I prefer having automatic line breaking as a default, and whatever needs fine tuning is handled manually. – so.very.tired Nov 7 '15 at 9:58
• @so.very.tired \raggedright is your friend – egreg Nov 7 '15 at 10:16

You can define the textwidth to have a certain value using package geometry. Alternatively, a parbox could be used, but they cannot be broken over pages. Use \raggedright to get non-justified text.

\documentclass{article}
\usepackage{amsmath}
\usepackage[parfill]{parskip}
\pagestyle{empty}
\usepackage{xcolor}
\definecolor{mywhite}{rgb}{1,1,1}
\definecolor{myblue}{RGB}{153,255,255}
%\color{mywhite}

\usepackage{geometry}
\geometry{textwidth=10cm}

\begin{document}
\raggedright
\begin{itemize}
\item
A compression technique used to reduce the bits needed
to encode symbols (e.g. letters).
\item
Based on the frequency of occurrence of a symbol in the data.
\item
Huffman code is optimal.
\begin{itemize}
\item To use our definitions and notations, given a text
containing $n$ different letters where $w_i$ is the frequency
of the $i$’th letter, Huffman Algorithm constructs
an Extended Binary Tree while minimizing $\sum_{i=1}^n w_il_i$.
\end{itemize}
\end{itemize}
\end{document}