4

Sometimes I need to indent several lines and display math text.

For example, to make some semantic proofs in logic.

Here is an example of how I'm currently doing indent

Suppose $\mathfrak{J} \vDash \text{KB}$

\setlength\parindent{24pt}
Then

\setlength\parindent{48pt}
$\mathfrak{J} \vDash \text{P(a,X)} \to \neg \text{P(b,X)}$

$\mathfrak{J} \vDash \text{P(a,n)}$

Therefore

\setlength\parindent{72pt}
$\mathfrak{J} \vDash \neg \text{P(b,n)} $

\setlength\parindent{24pt}
Also,

\setlength\parindent{48pt}
$\mathfrak{J} \vDash \neg \text{ P(X, n)} \to \neg \text{E(X)}$

Pretty bad, because I have to use \setlength\parindent{24pt} every time I need to change indentation. Here is the result I need:

Suppose J ⊨ KB
    Then
        J ⊨ P(a,X) → ¬ P(b,X)
        J ⊨ P(a,n)
        Therefore
            J ⊨ ¬ P(b,n)
    Also,
        J ⊨ ¬ P(X,n) → ¬ E(X)

I wish I could have this indentation using only tabs, just like in plain text. Is that possible?

2 Answers 2

4
\documentclass{article}
\usepackage{amsmath,amssymb,listings}
\lstset{columns=fullflexible,keepspaces,mathescape}
\begin{document}
\begin{lstlisting}
Suppose $\mathfrak{J} \vDash \text{KB}$
    Then
        $\mathfrak{J} \vDash \text{P(a,X)} \to \neg \text{P(b,X)}$
        $\mathfrak{J} \vDash \text{P(a,n)}$
        Therefore
            $\mathfrak{J} \vDash \neg \text{P(b,n)} $
    Also,
        $\mathfrak{J} \vDash \neg \text{ P(X, n)} \to \neg \text{E(X)}$
\end{lstlisting}
\end{document}

enter image description here

1
  • Thanks! Sounds great
    – user248797
    Sep 23, 2021 at 15:40
4

This is one of the rare cases¹ where LaTeX's much ignored tabbing environment makes sense.

Here's an example of this for your code:

\begin{tabbing}
\hspace{24pt}\=\hspace{24pt}\=\hspace{24pt}\kill % ❶
Suppose $\mathfrak{J} \vDash \text{KB}$\\
\> Then \\ % ❷
\> \> $\mathfrak{J} \vDash \text{P(a,X)} \to \neg \text{P(b,X)}$\\
\> \> $\mathfrak{J} \vDash \text{P(a,n)}$\\
\> \> Therefore\\
\> \> \> $\mathfrak{J} \vDash \neg \text{P(b,n)} $ \\
\> Also, \\
\> \> $\mathfrak{J} \vDash \neg \text{ P(X, n)} \to \neg \text{E(X)}$
\end{tabbing}

We start out by setting our ``tab stops'' ❶. Each \= command² sets a tab stop and \kill at the end of the line tells LaTeX to not actually set the text specified.

Then we use \> to tab to each tab stop in turn using \\ to start a new line ❷.

In my deleted chapter, I had suggested tabbing as a means to do three things that have better solutions now: typesetting algorithms, pretty-printing code³ and multi-page tables, but for your case it's a pretty good fit.⁴


  1. Rare enough that I took out the chapter on tabbing from my LaTeX book.
  2. The tabbing environment steals some of the accent commands for its own use. As a result, you need to use \a=, \a' and \a` to get the macron, acute and grave accents.
  3. Although I have to say that I don't like the aesthetics of the default styling of the listings package.
  4. Another option that would be much more work would be to create a custom algorithm type with the algorithmicx package, but I suspect that would be more work than it's worth (and definitely more work than I care to do for a tex.se answer). I'd note that algorithmicx manages its indentation through subtly hidden nested list environments.
3
  • It seems like a similar approach would be to use \newcommand*{\tabs}[1]{\hspace{\tabs\parindent}}, and then you wouldn't need to worry about the tabbing environment.
    – Teepeemm
    Sep 23, 2021 at 15:14
  • THanks for the answer!
    – user248797
    Sep 23, 2021 at 15:40
  • @Teepeemm The tabbing environment provides some fancy abilities that aren't possible with that approach, for example, you can set the tab stops using a text template, or reset them mid-listing. The whole thing is rather clever, but doesn't really fit in well with the rest of LaTeX in some ways. (Your \newcommand won't work by the way.)
    – Don Hosek
    Sep 23, 2021 at 16:53

You must log in to answer this question.