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
884 stars 84 forks source link

% signs for line wrapping should be kept #459

Closed koppor closed 1 year ago

koppor commented 1 year ago

TLDR: % are moved to the end of the paragraph - and not kept.

-\href{https://github.com/latextemplates/LNCS/blob/main/paper.tex}{\texttt{pape%
+\href{https://github.com/latextemplates/LNCS/blob/main/paper.tex}{\texttt{pape
     r.tex}} uses Computer Modern font, microtype configuration, listings
...
-\href{https://github.com/latextemplates/LNCS/blob/main/paper-en-times-minted-c%
+\href{https://github.com/latextemplates/LNCS/blob/main/paper-en-times-minted-c
   leveref.tex}{\texttt{paper-en-times-minted.tex}} provides a template where
...
-feature\footnote{\url{https://docs.github.com/en/repositories/creating-and-man%
+feature\footnote{\url{https://docs.github.com/en/repositories/creating-and-man
     aging-repositories/creating-a-repository-from-a-template}} to create a new git
 repository hosted on GitHub containing the latest template files as single
-commit.
+commit.%%%

I have URLs in the paper, which are longer than 80chars. latexindent hard wraps them (which is "OKish")

To keep the URLs be working, I added % at the end of each line. When calling latexindent again, it moves the % down to the paragraph.

original .tex code

For end users, installing Node.js can be
tedious. Therefore, for each supported template, a separate GitHub repository
is offered. In that repository, default \verb+paper-*.tex+ files
are offered. For the \LNCS\
template,\footnote{\url{https://github.com/latextemplates/LNCS}}
\href{https://github.com/latextemplates/LNCS/blob/main/paper.tex}{\texttt{pape%
    r.tex}} uses the Computer Modern font, \texttt{microtype}
configuration, \texttt{listings}
configuration (including \JSON\ support),
\texttt{pdfcomment}\footnote{\url{https://ctan.org/pkg/pdfcomment}} for
\acro{TODO} marking,
and \LaTeX{} examples. To reduce the size of the
\verb+.tex+ file, no hints on writing a paper are included.

yaml settings

defaultIndent: '  '
modifyLineBreaks:
  textWrapOptions:
    columns: 79
    huge: wrap
verbatimEnvironments:
  markdown: 1

actual/given output

For end users, installing Node.js can be tedious. Therefore, for each
supported template, a separate GitHub repository is offered. In that
repository, default \verb+paper-*.tex+ files are offered. For the
\LNCS\ template,\footnote{\url{https://github.com/latextemplates/LNCS}}
\href{https://github.com/latextemplates/LNCS/blob/main/paper.tex}{\texttt{pape
    r.tex}} uses the Computer Modern font, \texttt{microtype} configuration,
\texttt{listings} configuration (including \JSON\ support),
\texttt{pdfcomment}\footnote{\url{https://ctan.org/pkg/pdfcomment}} for
\acro{TODO} marking, and \LaTeX{} examples. To reduce the size of the
\verb+.tex+ file, no hints on writing a paper are included.%

desired or expected output

For end users, installing Node.js can be tedious. Therefore, for each
supported template, a separate GitHub repository is offered. In that
repository, default \verb+paper-*.tex+ files are offered. For the
\LNCS\ template,\footnote{\url{https://github.com/latextemplates/LNCS}}
\href{https://github.com/latextemplates/LNCS/blob/main/paper.tex}{\texttt{pape%
    r.tex}} uses the Computer Modern font, \texttt{microtype} configuration,
\texttt{listings} configuration (including \JSON\ support),
\texttt{pdfcomment}\footnote{\url{https://ctan.org/pkg/pdfcomment}} for
\acro{TODO} marking, and \LaTeX{} examples. To reduce the size of the
\verb+.tex+ file, no hints on writing a paper are included.

anything else

For me, it would be OK, if \href and \url parameters would not be wrapped at all. Or moved to the beginning of the next line (if too long) and then NOT wrapped any more. -- Maybe, this can be configured, too? wrapUrls: 0 (no wrapping of urls, 1 behavior: just as now)

cmhughes commented 1 year ago

Thanks for this.

Have you seen https://latexindentpl.readthedocs.io/en/latest/sec-fine-tuning.html?highlight=Href#lst-finetuning4

Let me know if it helps!

Do you really want huge set to wrap? It slows down everything and may give undesirable results...

cmhughes commented 1 year ago

Any luck with the above?

cmhughes commented 1 year ago

demonstration 1

If we use

defaultIndent: '  '
modifyLineBreaks:
  textWrapOptions:
    columns: 79
    huge: wrap
verbatimEnvironments:
  markdown: 1

fineTuning:                                                      
  trailingComments:
    notPreceededBy: (?:(?<!pape))       # <!--- NEW BIT

then the output is

For end users, installing Node.js can be tedious. Therefore, for each
supported template, a separate GitHub repository is offered. In that
repository, default \verb+paper-*.tex+ files are offered. For the
\LNCS\ template,\footnote{\url{https://github.com/latextemplates/LNCS}}
\href{https://github.com/latextemplates/LNCS/blob/main/paper.tex}{\texttt{pape
    % r.tex}} uses the Computer Modern font, \texttt{microtype} configuration,
\texttt{listings} configuration (including \JSON\ support),
\texttt{pdfcomment}\footnote{\url{https://ctan.org/pkg/pdfcomment}} for
\acro{TODO} marking, and \LaTeX{} examples. To reduce the size of the
\verb+.tex+ file, no hints on writing a paper are included.

reference: https://latexindentpl.readthedocs.io/en/latest/sec-fine-tuning.html#lst-href2

demonstration 2

If we use

defaultIndent: '  '
modifyLineBreaks:
  textWrapOptions:
    columns: 79
    # huge: wrap   # <!---- COMMENTED OUT
verbatimEnvironments:
  markdown: 1

fineTuning:
  trailingComments:
    notPreceededBy: (?:(?<!pape))

then we receive

For end users, installing Node.js can be tedious. Therefore, for each
supported template, a separate GitHub repository is offered. In that
repository, default \verb+paper-*.tex+ files are offered. For the \LNCS\
template,\footnote{\url{https://github.com/latextemplates/LNCS}}
\href{https://github.com/latextemplates/LNCS/blob/main/paper.tex}{\texttt{pape%
    r.tex}} uses the Computer Modern font, \texttt{microtype} configuration,
\texttt{listings} configuration (including \JSON\ support),
\texttt{pdfcomment}\footnote{\url{https://ctan.org/pkg/pdfcomment}} for
\acro{TODO} marking, and \LaTeX{} examples. To reduce the size of the
\verb+.tex+ file, no hints on writing a paper are included.

I recommended not changing huge, reference: https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch.html#text-wrap-huge-tabstop-and-separator