Emacs is really smart about indentation. Unfortunately, you have to be even smarter to get it to do something new.
The easiest thing to do in this case is to customize the variable LaTeX-paragraph-commands
. By default, this is empty. If you add IF and STATE, then C-c C-q C-e
should respect your wishes and not jumble everything up together.
To do this, call M-x customize-variable LaTeX-paragraph-commands
, click the INS
button and add IF in the string box, click INS
again and add STATE
to a second string box. The click apply and save
.
Getting proper indentation of nested IF statements is going to be trickier. One approach is to customize the variables LaTeX-begin-regexp
and LaTeX-end-regexp
. The first defaults to begin\b
, and the second to end\b
. If you extend them to begin\b\|IF\b
and end\b\|ENDIF\b
respectively, Auctex will indent your IF blocks how you like.
To do this, call M-x customize-variable LaTeX-begin-regexp
and change begin\b
to begin\b\|IF\b
, and then click apply and save
. Do the same for LaTeX-end-regexp
, adding the \|ENDIF\b
bit.
However, if you don't close your IF blocks with an ENDIF, then the indentation doesn't return to normal when you leave your algorithmic environment. To get Auctex to properly handle un-ended IF blocks, you need to cook up a custom indentation function. I don't know how to do that yet, but may return when I do.
you've already separated the different elements, providing spaces between the distinct equations comprising each language and separately coding these equations as math (even
though the space between the first two is, probably inadvertently, omitted).
unfortunately, these spaces don't fall in a place that is optimal for tex to break the line.
the ultimate goal is for what is presented to be understood.
there are two parts to this recommendation.
first, the words "milk, curry, rice" are, as you say, constants, and as such should be
in a text font, preferably not italic in this context, even though they're part of the
math expression. as coded in your original, they are typeset as strings of variables
multiplied together. these could be coded as \mathrm{<word>}
, but that doesn't help
with line breaking. it also wouldn't leave spaces after the commas, although in this
situation, whether spaces are visible there or not wouldn't be misunderstood by a reader.
another way to approach these is to recognize them as text, and input them as, for example,
$\mathcal{C}_o=\{\text{milk, curry, rice}\}$
but this doesn't help with line breaking either, since in this context, the only
"allowable" break is after the equals sign.
so, second part of suggestion, take advantage of the fact that a reader isn't likely
to misunderstand what is meant if a line is broken within that string of constants,
and (temporarily) terminate the math after the opening brace, and reinstate it for the
ending brace:
$\mathcal{C}_o=\{$milk, curry, rice$\}$
to illustrate, using a forced line break for the "all math" instance, compare these
two lines:
here's the input that produced the image:
\begin{itemize}
\item The language of enquiry $\mathcal{L}$ is given by
$\mathcal{C}_o=\{milk, curry, rice\}$,\\
$\mathcal{R}_o=\{TastesHot, IsWhite, ContainsSpice, ContainsSugar\}$,
$\mathcal{F}_o=\{\}$.
\item The language of enquiry $\mathcal{L}$ is given by
$\mathcal{C}_o=\{$milk, curry, rice$\}$,
$\mathcal{R}_o=\{$TastesHot, IsWhite, ContainsSpice, ContainsSugar$\}$,
$\mathcal{F}_o=\{\}$.
\end{itemize}
(by the way, that's hardly a minimal example.)
Best Answer
The default indent for each block in the
algorithmic
environment (from thealgorithmicx
package) is\algorithmicindent
. As such, you can place the entire line of code in a top-aligned\parbox[t]
of adequate width or use thevarwidth
environment from thevarwidth
package, and indent as needed:Here is another alternative that could be used instead. It utilized the a modified version of
\Statex
, also supplied byalgorithmicx
. It now takes an optional argument indicating the number of indents to apply to the specific line, without numbering it (default for\Statex
).Note that I've stripped the unnecessary preamble content from the minimal working example (MWE) posted above. This is encouraged when posting problems/question - something that can compile that reproduces the problem.