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

different behavior for stdin and filename input #493

Closed vindex10 closed 11 months ago

vindex10 commented 11 months ago

original .tex code

\documentclass{article}   %% ... or norsk, nynorsk, USenglish
\usepackage[utf8]{inputenc}     %% ... or latin1
\usepackage[T1]{url}\urlstyle{sf}
\begin{document}
Hello!
\end{document}

yaml settings

defaultIndent: "    "
fileExtensionPreference:
  '': 1
  .tex: 2
  .sty: 3
  .cls: 4
  .bib: 5
modifyLineBreaks:
  oneSentencePerLine:
    manipulateSentences: 1              # 0/1
    removeSentenceLineBreaks: 1         # 0/1
    multipleSpacesToSingle: 1           # 0/1
    textWrapSentences: 1                # 1 disables main textWrap
    sentenceIndent: ""
    sentencesFollow:
      par: 1                          # 0/1
      blankLine: 1                    # 0/1
      fullStop: 1                     # 0/1
      exclamationMark: 1              # 0/1
      questionMark: 1                 # 0/1
      rightBrace: 1                   # 0/1
      commentOnPreviousLine: 1        # 0/1
      other: 0                        # regex
    sentencesBeginWith:
      A-Z: 1                          # 0/1
      a-z: 0                          # 0/1
      other: 0                        # regex
    sentencesEndWith:
      basicFullStop: 0                # 0/1
      betterFullStop: 1               # 0/1
      exclamationMark: 1              # 0/1
      questionMark: 1                 # 0/1
      other: \,                        # regex
    sentencesDoNOTcontain:
      other: \\begin                 # regex
  textWrapOptions:
    columns: 80                # 1 disables main textWrap
    multipleSpacesToSingle: 1
  environment:
    BeginStartsOnOwnLine: 1
    EndFinishesWithLineBreak: 1
  optionalArguments:
    CommaFinishesWithLineBreak: 1
    RSqBFinishesWithLineBreak: 1
  keyEqualsValuesBracesBrackets:
    KeyStartsOnOwnLine: 1
  items:
    ItemFinishesWithLineBreak: 1
  specialBeginEnd:
    SpecialBeginStartsOnOwnLine: 1
  verbatim:
    VerbatimBeginStartsOnOwnLine: 1
removeTrailingWhitespace:
  beforeProcessing: 1
  afterProcessing: 1
fineTuning:
  modifyLineBreaks:
      betterFullStop: |-
        (?:\.\s|,\s)

actual/given output

same as with either of these commands:

\documentclass{article}   %% ... or norsk, nynorsk, USenglish
\usepackage[utf8]
{inputenc}      %% ... or latin1
\usepackage[T1]
{url}\urlstyle{sf}
\begin{document}
Hello!
\end{document}

desired or expected output

same as with this command: latexindent -o tmp.tex -l ./latexindent.yaml -m orig.tex

\documentclass{article}   %% ... or norsk, nynorsk, USenglish
\usepackage[utf8]{inputenc}     %% ... or latin1
\usepackage[T1]{url}\urlstyle{sf}
\begin{document}
Hello!
\end{document}

Hi! Thank you for such a nice tool :)

I noticed that there is a difference in outputs when the tool is using file input vs stdin.

cmhughes commented 11 months ago

Thanks for this, I hope to look at it soon.

Is your yaml minimal?

cmhughes commented 11 months ago

I've been able to verify this undesired behaviour. The following yaml file is minimal

modifyLineBreaks:
  optionalArguments:
    RSqBFinishesWithLineBreak: 1

I need to look into this. It looks like indentPreamble is not being respected with STDIN

cmhughes commented 11 months ago

I believe that this is the problem line:

https://github.com/cmhughes/latexindent.pl/blob/189bbc765f050c677dadaa1cf4498342763bc306/LatexIndent/FileContents.pm#L139

In particular, the lookForPreamble field in defaultSettings.yaml doesn't have an entry for STDIN which is then not feeding through to this.

I should be able to get to this fairly soon, hopefully.

cmhughes commented 11 months ago

Fixed as of https://github.com/cmhughes/latexindent.pl/commit/a30cfa927b582f3a95cec1b345dd17d69fd3b3e8, I'll hopefully get this released soon. Please leave this open until released.

thanks again for reporting!

cmhughes commented 11 months ago

fixed and released at https://github.com/cmhughes/latexindent.pl/releases/tag/V3.23.4, uploaded to ctan. thanks again

vindex10 commented 11 months ago

Thank you! That was a super quick reaction, appreciate a lot!