Skip to content
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

Translate single quoted strings in -y / --yaml switches #296

Closed
XuehaiPan opened this issue Nov 3, 2021 · 4 comments · Fixed by #297
Closed

Translate single quoted strings in -y / --yaml switches #296

XuehaiPan opened this issue Nov 3, 2021 · 4 comments · Fixed by #297
Labels
contribution Thank you to the contributor! implemented implemented tag means that either an enhancement or feature request has been implemented, or bugfix

Comments

@XuehaiPan
Copy link
Contributor

XuehaiPan commented Nov 3, 2021

Please provide the following when posting an issue:

original .tex code

Please paste your .tex code here. Please note in answering your issue, I may add the code you provide to the test-cases directory. Please detail explicitly if you would prefer me not to do so..

This is verbatim7.tex in test cases.

\begin{surround}
before text \begin{latexcode}
    body text
      body text
        body text \begin{pythoncode}
            for i in range(10):
                print("Hello, world!")
        \end{pythoncode} body text
body text
\end{latexcode} after text

before text \begin{latexcode*}{linenos=true}
  body text
    body text
      body text \begin{pythoncode}
          for i in range(10):
              print("Hello, world!")
      \end{pythoncode} body text
body text
\end{latexcode*} after text
\end{surround}

yaml settings

Please paste your YAML settings (if any) here

$ latexindent -w -t -y="defaultIndent:'  ',verbatimEnvironments:nameAsRegex:name:'\\w+code\\*?'" verbatim7.tex

actual/given output

Please paste the output you receive here

\begin{surround}
  before text \begin{latexcode}
    body text
    body text
    body text \begin{pythoncode}
      for i in range(10):
      print("Hello, world!")
    \end{pythoncode} body text
    body text
  \end{latexcode} after text

  before text \begin{latexcode*}{linenos=true}
    body text
    body text
    body text \begin{pythoncode}
      for i in range(10):
      print("Hello, world!")
    \end{pythoncode} body text
    body text
  \end{latexcode*} after text
\end{surround}

indent.log shows that the regex expression contains single quotes and they are not removed.

INFO:  latexindent version 3.13, 2021-10-30, a script to indent .tex files
       latexindent lives here: /usr/local/texlive/2021/texmf-dist/scripts/latexindent/
       Wed Nov  3 21:48:33 2021
       Filename: verbatim7.tex
INFO:  Processing switches:
       -t|--trace: Trace mode active (you have used either -t or --trace)
       -w|--overwrite: Overwrite mode active, will make a back up of verbatim7.tex first
       -y|--yaml: YAML settings specified via command line
INFO:  Directory for backup files and indent.log: .
INFO:  YAML settings read: defaultSettings.yaml
       Reading defaultSettings.yaml from /usr/local/texlive/2021/texmf-dist/scripts/latexindent/defaultSettings.yaml
INFO:  YAML settings read: indentconfig.yaml or .indentconfig.yaml
       Home directory is /home/PanXuehai (didn't find either indentconfig.yaml or .indentconfig.yaml)
       To specify user settings you would put indentconfig.yaml here: /home/PanXuehai/indentconfig.yaml
       Alternatively, you can use the hidden file .indentconfig.yaml as: /home/PanXuehai/.indentconfig.yaml
INFO:  YAML settings read: -y switch
       YAML setting: defaultIndent:'  '
       YAML setting: verbatimEnvironments:nameAsRegex:name:'\w+code\*?'
       Updating mainSettings with defaultIndent:   
       Updating mainSettings with verbatimEnvironments: nameAsRegex: name: '\w+code\*?'
INFO:  Backup procedure (-w flag active):
       copying verbatim7.tex to ./verbatim7.bak0
       Backup file: ./verbatim7.bak0
       verbatim7.tex will be overwritten after indentation

desired or expected output

Please paste your desired/expected output here; that is, what do you want the output to look like

Double quoted strings work fine.

$ latexindent -w -t -y="defaultIndent:'  ',verbatimEnvironments:nameAsRegex:name:\"\\w+code\\*?\"" verbatim7.tex
\begin{surround}
  before text \begin{latexcode}
    body text
      body text
        body text \begin{pythoncode}
            for i in range(10):
                print("Hello, world!")
        \end{pythoncode} body text
body text
\end{latexcode} after text

  before text \begin{latexcode*}{linenos=true}
  body text
    body text
      body text \begin{pythoncode}
          for i in range(10):
              print("Hello, world!")
      \end{pythoncode} body text
body text
\end{latexcode*} after text
\end{surround}

indent.log shows we removed double quotes.

INFO:  latexindent version 3.13, 2021-10-30, a script to indent .tex files
       latexindent lives here: /usr/local/texlive/2021/texmf-dist/scripts/latexindent/
       Wed Nov  3 21:52:54 2021
       Filename: verbatim7.tex
INFO:  Processing switches:
       -t|--trace: Trace mode active (you have used either -t or --trace)
       -w|--overwrite: Overwrite mode active, will make a back up of verbatim7.tex first
       -y|--yaml: YAML settings specified via command line
INFO:  Directory for backup files and indent.log: .
INFO:  YAML settings read: defaultSettings.yaml
       Reading defaultSettings.yaml from /usr/local/texlive/2021/texmf-dist/scripts/latexindent/defaultSettings.yaml
INFO:  YAML settings read: indentconfig.yaml or .indentconfig.yaml
       Home directory is /home/PanXuehai (didn't find either indentconfig.yaml or .indentconfig.yaml)
       To specify user settings you would put indentconfig.yaml here: /home/PanXuehai/indentconfig.yaml
       Alternatively, you can use the hidden file .indentconfig.yaml as: /home/PanXuehai/.indentconfig.yaml
INFO:  YAML settings read: -y switch
       YAML setting: defaultIndent:'  '
       YAML setting: verbatimEnvironments:nameAsRegex:name:"\w+code\*?"
       Updating mainSettings with defaultIndent:   
       quote found in -y switch
       key: verbatimEnvironments:nameAsRegex:name:
       value: \w+code\*?
       Updating mainSettings with verbatimEnvironments: nameAsRegex: name: \w+code\*?
INFO:  Backup procedure (-w flag active):
       ./verbatim7.bak0 already exists, incrementing by 1... (see maxNumberOfBackUps and onlyOneBackUp)
       copying verbatim7.tex to ./verbatim7.bak2
       Backup file: ./verbatim7.bak2
       verbatim7.tex will be overwritten after indentation

anything else

Please put any comments or anything else here :)

@cmhughes
Copy link
Owner

cmhughes commented Nov 3, 2021

Thanks for this, I'll l review soon, I hope. Development is slow at the moment because of work pressures. Apologies

@cmhughes cmhughes added the contribution Thank you to the contributor! label Nov 4, 2021
@cmhughes
Copy link
Owner

cmhughes commented Nov 7, 2021

Thanks for this.

The following seems to work, with no single quotes:

latexindent.pl -t -y="defaultIndent:'  ',verbatimEnvironments:nameAsRegex:name:\\w+code\\*?" myfile.tex

Do you need the single quotes?

@XuehaiPan
Copy link
Contributor Author

XuehaiPan commented Nov 7, 2021

Do you need the single quotes?

In my use cases, no. latexindent works properly with and without double quotes, but produces wrong results with single quotes. If the string contains spaces, the quotes are needed.

I prefer to mark this issue as an enhancement rather than a bug (cause it works without quotes). But I still think it is necessary, for many users, it is more intuitive to add quotes around strings. I spent hours to find out why my --yaml switches not working but the same configuration in latexindent.yaml works. This improvement will reduce similar issues in the future.

As for why I'm using single quotes rather than double quotes (works fine), I'm using latexindent integrated with LaTeX-Workshop on VS Code. VS Code uses JSON-format in settings and I will need to escape the double quotes multiple times:

// double quotes
"latex-workshop.latexindent.args": [
    "-c",
    "%DIR%/",
    "%TMPFILE%",
    "-y=defaultIndent: '%INDENT%',verbatimEnvironments:codeblock:name:\"\\w+code\\*?\""
]

// single quotes
"latex-workshop.latexindent.args": [
    "-c",
    "%DIR%/",
    "%TMPFILE%",
    "-y=defaultIndent: '%INDENT%',verbatimEnvironments:codeblock:name:'\\w+code\\*?'"
]

@cmhughes cmhughes added the implemented implemented tag means that either an enhancement or feature request has been implemented, or bugfix label Nov 7, 2021
cmhughes added a commit that referenced this issue Nov 12, 2021
@cmhughes cmhughes mentioned this issue Nov 12, 2021
@cmhughes
Copy link
Owner

Implemented at https://github.com/cmhughes/latexindent.pl/releases/tag/V3.13.1, thanks again for your contribution to the project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution Thank you to the contributor! implemented implemented tag means that either an enhancement or feature request has been implemented, or bugfix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants