cmhughes / latexindent.pl

Perl script to add indentation (leading horizontal space) to LaTeX files. It can modify line breaks before, during and after code blocks; it can perform text wrapping and paragraph line break removal. It can also perform string-based and regex-based substitutions/replacements. The script is customisable through its YAML interface.
GNU General Public License v3.0
868 stars 84 forks source link

`oneSentencePerLine` also breaks lines on abbreviations #557

Open reneas opened 3 weeks ago

reneas commented 3 weeks ago

So this is maybe a little tricky because it is happening in tables (but not only)... Maybe one could write a regex that excludes certain abbreviations like max. or ca. from being treated as the end of a sentence? Unfortunately I'm not that familiar with regex structure so I don't really know how to do that. But maybe there is an easier soluton that I overlooked?

original .tex code

\begin{table}[ht"]
\centering
\caption{Empfohlene Prozessparameter für die Entgratung mit Fräser \& Ausgleichshalter}
\label{tab:empfohlene_parameter_frser}
\begin{tabular}{@{}lll@{}}
\toprule
\textbf{Parameter}      & \textbf{Einheit}  & \textbf{Wert}   \\ \midrule
Drehzahl $n$            & $\tfrac{U}{min}$  & 6.000 - 8.000   \\
max. Drehzahl $n_{max}$ & $\tfrac{U}{min}$  & 10.000          \\
Vorschub $v_f$          & $\tfrac{mm}{min}$ & 2.000 - 10.0000 \\
Zustellung axial $a_p$  & $[ mm ]$          & ca. $0,25*d_t$  \\
Zustellung radial $a_e$ & $[ mm ]$          & ca. $0,3*d_t$   \\ \bottomrule
\end{tabular}
\end{table}

yaml settings

mysettings.txt ← My settings file: changes.txtdiff file between defautlSettings.yaml and mysettings.yaml: [

actual/given output

\begin{table}[ht!]
    \centering
    \caption{Empfohlene Prozessparameter für die Entgratung mit Fräser \& Ausgleichshalter}
    \label{tab:empfohlene_parameter_frser}
    \begin{tabular}{@{}lll@{}}
        \toprule
        \textbf{Parameter}      & \textbf{Einheit} & \textbf{Wert} \\ \midrule
        Drehzahl $n$            & $\tfrac{U}{min}$ & 6.000 - 8.000 \\
        max.
        Drehzahl $n_{max}$      & $\tfrac{U}{min}$ & 10.000        \\ Vorschub $v_f$ & $\tfrac{mm}{min}$ & 2.000 - 10.0000 \\ Zustellung axial $a_p$ & $[ mm ]$ & ca.
        $0,25*d_t$                                                 \\
        Zustellung radial $a_e$ & $[ mm ]$         & ca. $0,3*d_t$ \\ \bottomrule
    \end{tabular}
\end{table}

desired or expected output

\begin{table}[ht!]
    \centering
    \caption{Empfohlene Prozessparameter für die Entgratung mit Fräser \& Ausgleichshalter}
    \label{tab:empfohlene_parameter_frser}
    \begin{tabular}{@{}lll@{}}
        \toprule
        \textbf{Parameter}      & \textbf{Einheit}  & \textbf{Wert}   \\ \midrule
        Drehzahl $n$            & $\tfrac{U}{min}$  & 6.000 - 8.000   \\
        max. Drehzahl $n_{max}$ & $\tfrac{U}{min}$  & 10.000          \\
        Vorschub $v_f$          & $\tfrac{mm}{min}$ & 2.000 - 10.0000 \\
        Zustellung axial $a_p$  & $[ mm ]$          & ca. $0,25*d_t$  \\
        Zustellung radial $a_e$ & $[ mm ]$          & ca. $0,3*d_t$   \\ \bottomrule
    \end{tabular}
\end{table}
cmhughes commented 2 weeks ago

Thanks for this.

Using the following

modifyLineBreaks:
  oneSentencePerLine:
    manipulateSentences: 1              # 0/1
    sentencesDoNOTcontain:
      other: (?:\\begin|\\\\)

gives the output

\begin{table}[ht"]
    \centering
    \caption{Empfohlene Prozessparameter für die Entgratung mit Fräser \& Ausgleichshalter}
    \label{tab:empfohlene_parameter_frser}
    \begin{tabular}{@{}lll@{}}
        \toprule
        \textbf{Parameter}      & \textbf{Einheit}  & \textbf{Wert}   \\ \midrule
        Drehzahl $n$            & $\tfrac{U}{min}$  & 6.000 - 8.000   \\
        max. Drehzahl $n_{max}$ & $\tfrac{U}{min}$  & 10.000          \\
        Vorschub $v_f$          & $\tfrac{mm}{min}$ & 2.000 - 10.0000 \\
        Zustellung axial $a_p$  & $[ mm ]$          & ca. $0,25*d_t$  \\
        Zustellung radial $a_e$ & $[ mm ]$          & ca. $0,3*d_t$   \\ \bottomrule
    \end{tabular}
\end{table}

For reference, see https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch.html#onesentenceperline-sentencesdonotcontain

reneas commented 2 weeks ago

Oh great! So with that regex I can also manipulate if other abbreviations in the middle of the sentence should be treated as end of sentences? Or would I rather modify the fine tuning of the better full stop like shown here? I just found out that AI is my best friend for writing regexes so that should not be a problem anymore :)

cmhughes commented 2 weeks ago

You can choose!

On Mon, 26 Aug 2024, 08:42 Hannez Kannez, @.***> wrote:

Oh great! So with that regex I can also manipulate if other abbreviations in the middle of the sentence should be treated as end of sentences? Or would I rather modify the fine tuning of the better full stop like shown here https://latexindentpl.readthedocs.io/en/latest/sec-fine-tuning.html#lst-finetuning ? I just found out that AI is my best friend for writing regexes so that should not be a problem anymore :)

— Reply to this email directly, view it on GitHub https://github.com/cmhughes/latexindent.pl/issues/557#issuecomment-2309555227, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ7CYBIJIWU2FUY6LK3OYLZTLL6ZAVCNFSM6AAAAABMWM6FGWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBZGU2TKMRSG4 . You are receiving this because you commented.Message ID: @.***>

reneas commented 2 weeks ago

So what I did now is a combination of both. I used your suggested

sentencesDoNOTcontain:
      other: (?:\\begin|\\\\)

And the modification of the betterFullStop

    betterFullStop: |-
      (?x)                                # ignore spaces in the below
      (?:                                 #
        \.\)                              # .)
        (?!\h*[a-z])                      # not *followed by* a-z
      )                                   #
      |                                   # OR
      (?:                                 #
        (?<!                              # not *preceded by*
          (?:                             #
            (?:z)                         #
            |                             #
            (?:[zZ]\.[tT])                # z.T.
            |                             #
            (?:al)                        # et al.
            |                             #
            (?:[zZ]\.[bB])                # z.B.
            |                             #
            (?:[bB]zw)                    # bzw.
            |                             #
            (?:[mM]ax)                    # max.
            |                             #
            (?:[uU]\.[aA)                 # u.a.
            |                             #
            (?:[cC][aA])                  # ca
            |                             #
...

But some occurences still don't get recognized if there is a \\ or a \begin{quote}

\subsection{(Automatisiertes) maschinelles mechanisches Entgraten}
        Wie bereits erwähnt, eignen sich nicht alle Verfahren des mechanischen Entgratens für die Anwendung auf einer CNC-Maschine.
        Es existiert allerdings eine Palette an Möglichkeiten, Dieses durchzuführen.
        Hierzu gehören vor allem verschiedene Formen von Fräsern und Bürsten mit verschiedensten Geometrien und aus zahlreichen Materialien.
        Diese können auch schwer zugängliche Stellen zuverlässig entgraten.
        \\
        Viele mechanische Entgratungsprozesse für komplexere Bauteile z.
        B.
        in der Luft- und Raumfahrt werden auch heute noch von Hand durchgeführt, da die zu entgratenden Teile eine Vielzahl an Graten besitzen, die teilweise sehr schwer zu erreichen sein können.

or

               \begin{quote}
            \textit{\textbf{Grat} ist ein auf einer Werkstückoberfläche bei der Herstellung eines Werkstücks entstandener Körper, der über die angestrebte und tatsächlich vorhandene Werkstückoberfläche hinausragt und im Vergleich zum Werkstück meist ein geringeres Volumen hat, unerwünscht, aber z.
                T. unumgänglich ist.
            }
        \end{quote}

Where as here it works as intended (with the z.B. in the first item):

    \begin{itemize}
        \item \textbf{Einschränkung der Funktion:}
              Grate können die Funktionalität eines Bauteils beeinträchtigen und eine Montage erschweren/unmöglich machen (z.B. bei ineinander einzuführenden Bauteilen).
        \item \textbf{Ergonomie:}
              Grate können scharfkantig sein und somit eine Verletzungsgefahr bei Bearbeitung und Handhabung darstellen.
        \item \textbf{Ästhetik:}
              Grate können die Optik eines Bauteils beeinträchtigen und somit die Qualität des Bauteils mindern.
    \end{itemize}