texstudio icon indicating copy to clipboard operation
texstudio copied to clipboard

autogenerated cwl and regular highlighter have issue with spaces

Open mbertucci47 opened this issue 1 year ago • 0 comments

Environment

  • TeXstudio: 4.3.0beta3
  • Qt: 6.3.0
  • OS: Windows 10
  • TeX distribution: miktex

Expected behavior

It's increasingly common for package and class authors to use spaces in their code to make it more readable (see acro, tabularray, ctex, and so on for examples).

Actual behavior

This causes both the autogenerated cwl and regular in-document highlighting to fail in some cases. For example the class file myclass.cls

% myclass.cls
\ProvidesExplClass {myclass} {2022-07-29} {v1} {custom class}
\LoadClass { book }
\RequirePackage { etoolbox }

\NewDocumentCommand{\foo}{m}{stuff}
\NewDocumentCommand{ \varfoo }{ m }{stuff}
\NewDocumentCommand {\varvarfoo} {m} {stuff}
\NewDocumentCommand { \varvarvarfoo } { m } {stuff}
\NewDocumentCommand\foovar{m}{stuff}
\NewDocumentCommand \foovarvar { m } {stuff}

produces the autogenerated cwl

# autogenerated by txs
#include:etoolbox
\foovarvar{arg1}#S
\foovar{arg1}#S
\foo{arg1}#S
\varvarfoo{arg1}#S

It does not recognize the \LoadClass because of the spaces, but does recognize the \RequirePackage even though it uses the same pattern of spaces. Also, \NewDocumentCommand is not recognized if followed by either "{-space" or "space-{-space".

The same pattern holds for the completer if given in a .tex file, e.g.

Screenshot 2022-07-29 111014

Here's the source for this example:

\documentclass{article}

\NewDocumentCommand{ \mycmd } { } {stuff}
\NewDocumentCommand { \varmycmd } { } {stuff}

\begin{document}
\mycmd
\varmycmd
\end{document}

mbertucci47 avatar Jul 29 '22 17:07 mbertucci47