Skip to content

Question about indentation inside braces #587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
domi413 opened this issue Apr 15, 2025 · 7 comments
Open

Question about indentation inside braces #587

domi413 opened this issue Apr 15, 2025 · 7 comments
Labels
documentation focused on updating the documentation; files to be updated are documentation/*.tex

Comments

@domi413
Copy link

domi413 commented Apr 15, 2025

example file

\documentclass[10pt, a4paper]{article}
\usepackage{amsmath}

\begin{document}
\section{first section}
\[ f(x) = \sqrt{e^x} = \left(e^{x}\right)^{\dfrac{1}{2}} = e^{\dfrac{1}{2}x} \]

{ \small
\begin{align*}
	f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
\end{align*}
}

\( x_0 \)

{ \small
		\begin{align*}
			f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
		\end{align*}
	}

hello world

	{ \small
		\begin{align*}
			f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
		\end{align*}
	}

\subsection{subsection}
{ \small
	\begin{align*}
		f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
	\end{align*}
}

\section{Other section}
 { \small
  \begin{align*}
	  f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
  \end{align*}
 }
\end{document}

yaml settings

defaultIndent: "\t"

removeTrailingWhitespace:
  beforeProcessing: 0
  afterProcessing: 1

indentAfterItems:
  itemize: 1
  itemize*: 1
  enumerate: 1
  enumerate*: 1
  description: 1
  description*: 1
  list: 1

noAdditionalIndent:
  multicols:
    body: 1

modifyLineBreaks:
  textWrapOptions:
    columns: 80
    # columns: -1
    blocksFollow:
      other: \\item|\\newline|\\begin\{quote\}|\\end\{figure\}
      commentOnPreviousLine: 0
    blocksBeginWith:
      other: .*
    blocksEndBefore:
      other: \\newline|\\begin|\\end|\\vspace|\\\\|\\pagenumbering|\\pagestyle|\\tableofcontents|\\clearpage|\\bigskip|\\smallskip|\\medskip|\\usepackage|\\setlength|\\definecolor|\\\[|\\\(

replacements:
  # Replace $$...$$ with \[...\]
  - substitution: 's/\$\$(.*?)\$\$/\\[$1\\]/sg'
    when: before

  # Replace $...$ with \(...\)
  - substitution: 's/\$(.*?)\$/\\($1\\)/sg'
    when: before

  # Standardize spacing within \( ... \)
  - substitution: 's/\\\(\s*(.*?)\s*\\\)/\\( $1 \\)/sg'
    when: before

  # Standardize spacing within \[ ... \]
  - substitution: 's/\\\[\s*(.*?)\s*\\\]/\\[ $1 \\]/sg'
    when: before

actual/given output

\documentclass[10pt, a4paper]{article}
\usepackage{amsmath}

\begin{document}
\section{first section}
\[ f(x) = \sqrt{e^x} = \left(e^{x}\right)^{\dfrac{1}{2}} = e^{\dfrac{1}{2}x} \]

{ \small
\begin{align*}
	f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
\end{align*}
}

\( x_0 \)

{ \small
		\begin{align*}
			f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
		\end{align*}
	}

hello world

	{ \small
		\begin{align*}
			f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
		\end{align*}
	}

\subsection{subsection}
{ \small
	\begin{align*}
		f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
	\end{align*}
}

\section{Other section}
 { \small
  \begin{align*}
	  f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
  \end{align*}
 }
\end{document}

desired or expected output

\documentclass[10pt, a4paper]{article}
\usepackage{amsmath}

\begin{document}
\section{first section}
\[ f(x) = \sqrt{e^x} = \left(e^{x}\right)^{\dfrac{1}{2}} = e^{\dfrac{1}{2}x} \]

{ \small
\begin{align*}
	f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
\end{align*}
}

\( x_0 \)

{ \small
\begin{align*}
	f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
\end{align*}
}

hello world

{ \small
\begin{align*}
	f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
\end{align*}
}

\subsection{subsection}
{ \small
\begin{align*}
	f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
\end{align*}
}

\section{Other section}
 { \small
  \begin{align*}
	  f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
  \end{align*}
 }
\end{document}

anything else

Hey,

I played around with some line wrapping options and I experienced that after a \[ \] there is no indentation inside the {}, after a subsection there is one tab indentation and after a section there is 1/2 tab indentation.

Is there an option to make this consistent e.g. never indent the code inside {} like after the \[ \]?

Thanks for looking into this.

EDIT: some additional examples

@cmhughes
Copy link
Owner

Have you tried

noAdditionalIndentGlobal:
  UnNamedGroupingBracesBrackets: 1

@domi413
Copy link
Author

domi413 commented Apr 15, 2025

\documentclass[10pt, a4paper]{article}
\usepackage{amsmath}

\begin{document}
\section{first section}
\[ f(x) = \sqrt{e^x} = \left(e^{x}\right)^{\dfrac{1}{2}} = e^{\dfrac{1}{2}x} \]

{ \small
\begin{align*}
	f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
\end{align*}
}

\( x_0 \)

{ \small
	\begin{align*}
		f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
	\end{align*}
}

hello world

	{ \small
		\begin{align*}
			f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
		\end{align*}
	}

\subsection{subsection}
{ \small
	\begin{align*}
		f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
	\end{align*}
}

\section{Other section}
 { \small
  \begin{align*}
	  f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
  \end{align*}
 }
\end{document}

A bit better compared to the previous result, but still some odd formatting

@cmhughes
Copy link
Owner

Can you make sure this is as minimal and clear as possible please? One specific example at a time.

@domi413
Copy link
Author

domi413 commented Apr 19, 2025

sorry for the delay.

Here's a minimal .latexindent.yaml

defaultIndent: "\t"

noAdditionalIndentGlobal:
  UnNamedGroupingBracesBrackets: 1

input tex file:

\documentclass[10pt, a4paper]{article}
\usepackage{amsmath}

\begin{document}
\( x_0 \)

{ \small
	\begin{align*}
		f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
	\end{align*}
}
\end{document}

desired output:

\documentclass[10pt, a4paper]{article}
\usepackage{amsmath}

\begin{document}
\( x_0 \)

{ \small
\begin{align*}
	f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
\end{align*}
}
\end{document}

actual output:

\documentclass[10pt, a4paper]{article}
\usepackage{amsmath}

\begin{document}
\( x_0 \)

{ \small
	\begin{align*}
		f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
	\end{align*}
}
\end{document}

As you can see, the \begin{align*} is indented, but it should not.

@cmhughes
Copy link
Owner

Thanks for this.

Using the following gives your desired output

defaultIndent: "\t"

noAdditionalIndent:
  always-un-named:
    body: 1
    mandatoryArguments: 1
    optionalArguments: 1

This is sort of mentioned in https://latexindentpl.readthedocs.io/en/latest/sec-default-user-local.html#unnamedgroupingbracesbrackets but I don't think it has enough details.

I'll update the documentation to cover this, so please leave this issue open :)

@cmhughes cmhughes added the documentation focused on updating the documentation; files to be updated are documentation/*.tex label Apr 19, 2025
@domi413
Copy link
Author

domi413 commented Apr 19, 2025

Hey, thanks for the answer :)

unfortunately, it looks like that those configs "only" fixes 1/4 cases.

Here are the remaining cases, that (with the above formatter settings) still have some indenation

\documentclass[10pt, a4paper]{article}
\usepackage{amsmath}

\begin{document}
hello world
	{ \small
		\begin{align*}
			f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
		\end{align*}
	}

\subsection{subsection}
{ \small
	\begin{align*}
		f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
	\end{align*}
}

\section{Other section}
 { \small
  \begin{align*}
	  f(x) & = e^{\dfrac{1}{2} x} &  & \Rightarrow f(0) = e^0 = 1 \\
  \end{align*}
 }
\end{document}

@cmhughes
Copy link
Owner

The following gives your desired output:

defaultIndent: "\t"

noAdditionalIndentGlobal:
  mandatoryArguments: 1
  namedGroupingBracesBrackets: 1

indentRules:
  section: ''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation focused on updating the documentation; files to be updated are documentation/*.tex
Projects
None yet
Development

No branches or pull requests

2 participants