Solutons Lounge

alignment – How to format a LaTeX input file to adapt equations for different layouts in multiple documents? – TeX


tldr:
I have a shared LaTeX input file containing a long equation (./theorem.tex). When included in a wide single-column document (notes.tex), the equation displays properly in one line. However, in a narrower multi-column layout (cheatsheet.tex), the equation overflows into the next column. How can I modify the shared input file to ensure the equation fits neatly in the cheatsheet (e.g., with line breaks) while still displaying in a single line in the notes?


I’m trying to compile a cheatsheet and a set of notes from the same input file.

Specifically, my input file look something like this:

\section{Some fancy theorem}

This is a fancy theorem:
\begin{equation*}
\prod_{n=1}^{\infty}\left(1-x^{n}\right)=\sum_{k=-\infty}^{\infty}\left(-1\right)^{k}x^{k\left(3k-1\right)/2}=1+\sum_{k=1}^\infty(-1)^k\left(x^{k(3k+1)/2}+x^{k(3k-1)/2}\right).
\end{equation*}

Suppose the file above is ./theorem.tex.

Now we have two sets of files:

notes.tex, which looks like:

\documentclass[11pt]{article}
\usepackage[a4paper, margin=1.2in]{geometry}
\usepackage{amsmath, amsfonts, mathtools, amsthm, amssymb}

\title{\textbf{Notes}}

\begin{document}

\maketitle

\input{./theorem.tex}

\end{document}

and cheatsheet.tex which has the form:

\documentclass[11pt,landscape]{article}
\usepackage{multicol}
\usepackage[landscape]{geometry}

\usepackage{amsmath, amsfonts, mathtools, amsthm, amssymb}

\begin{document}

\begin{multicols}{3}

\begin{center}
     \Large{\textbf{Cheatsheet}} \\
\end{center}

\input{./theorem.tex}

\end{multicols}
\end{document}

As cheatsheet.tex has 3 columns, the long equation doesn’t fit into a single column and spills into the next one. On the other hand, it displays correctly in notes.tex as there is a wider space for it to fit.

Is it possible to modify the input file (./theorem.tex) in a way that the equation will fit within the column for cheatsheet.tex (i.e with a line break (or two) somewhere within) and also display in a single line in notes.tex.

Ideally I want a single input file so that I can compile both the cheatsheet and notes simultaneously.



Source link

Exit mobile version