Closed muzimuzhi closed 5 years ago
I have implemented two commands in the cwl, see commit 99cafd4f0df6c49319cdc13b9891fc7672b8cdff
You can do the rest ...
The added lines to cwl file only recognize usages with braces like
\newbox{\somebox} % here txs recognizes \somebox as a new cmd
...
\somebox % here txs highlights \somebox as normal cmd
But what I want, and what is usually used in latex package source files is the form without braces:
\newbox\someBox % here txs highlights both \someBox as "unrecognized command"
...
\someBox
That is to say, commit https://github.com/texstudio-org/texstudio/commit/99cafd4f0df6c49319cdc13b9891fc7672b8cdff does not solve the question shown in the screenshot I have posted:
PS: Yes, the with-brace form (\newbox{\someBox}
) is a valid form, but the no-brace form is the form most latex package writers use. For example, the latex2e kernel consistently uses the no-brace form. This means, txs will provides wrong highlight when openning package source files.
The following may provide a clearer description about my original question (or request)
\newbox
to support usages like \newbox\someBox
where \someBox
will be recognized as new defined command?And following is my trial and guess when I opened this isse
\newbox%<cmd%>#d
), I guessed that it doesn't support. And I directly used my guess in the original post.\newcount\someCount
by specially handling \newcount
. (See the linked code lines in original post.) Hence I guess if we can support more \newXXX
things by changing the bool expression to something like
if (cmd == "\\newcount" || cmd == "\\newbox" || ...)
here it works fine
have you placed a tex.cwl in your .config/texstudio/completion/user ?
Your commit does meet my original request. I am so sorry.
Before today, I used a cwl-test.cwl
file containing a line \newbox{cmd}#dS
and a test tex file
\documentclass{article}
\usepackage{cwl-test}
\newbox\xxx
\newcount\zzz
\begin{document}
\xxx
\zzz
\end{document}
Then the problem persists when I directly open txs with the tex file. But when I delete and then re-type in the line \newbox\xxx
in tex file, it works.
I will provide the rest cwl lines.
Commit https://github.com/texstudio-org/texstudio/commit/d538bab7c91e9b845e0be698d1aac49b7e9b2d77 is also related to (or resulted from) this issue.
As far as I guess, since cwl file only supports options inside braces (
{}
,[]
, etc), commands that normally used without braces around their arguments and defines (mostly one of) their arguments as new macros are specially treated inlatexdocument.cpp
. For example,However, there are other command that share the same syntax with
\newcount
but have not been specially treated. This will cause wrong highlight effect in txs, see The full list of these\newcount
-like commands isPS: These macros, plus
\newcount
, were originally introduced in plain tex format, and were then adopted by latex2e format. Hence one can see the occurrences of them both in documents about tex with plain tex (liketexdoc texbytopic
, Chap. 31) and in documents about latex2e (liketexdoc source2e
, Sec. b.9).The related source lines could be https://github.com/texstudio-org/texstudio/blob/a7fd0a3dc064f685d68b8a6792bb825f4669a085/src/latexdocument.cpp#L838-L852