Skip to content

TeXStudio markiert fehlerhaft korrekten Code. #4036

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

Open
Axomas opened this issue Mar 27, 2025 · 3 comments
Open

TeXStudio markiert fehlerhaft korrekten Code. #4036

Axomas opened this issue Mar 27, 2025 · 3 comments

Comments

@Axomas
Copy link

Axomas commented Mar 27, 2025

Hallo,

In letzter Zeit beobache ich, dass TeXStudio fälschlicherweise korrekten Code als Fehler markiert.
Das Kompilieren funktioniert einwandfrei.

Beispiel:

Image

Im Code
\addplot[blue, thick, samples=100] {1.23 * exp(2/3 * x) * x^2};

wird das "^" rot markiert.

Das ist sehr seltsam. Ein Bug?
Gruß A.

@Axomas Axomas changed the title TeXStudio markiert fehlerhaft korrektes Code. TeXStudio markiert fehlerhaft korrekten Code. Mar 27, 2025
@muzimuzhi
Copy link
Contributor

Im Code \addplot[blue, thick, samples=100] {1.23 * exp(2/3 * x) * x^2};

wird das "^" rot markiert.

The braced argument in \addplot[<options>] {<math expression>}; accepts a math expression, which has a special syntax provided by tikz package, one of the dependencies of pgfplots package.

Currently the syntax highlighter and cwl file format of TeXstudio understand only the most common modes: text mode, math mode, and verbatim mode. The syntax of (pgfmath) math expression is not in that list.

In math expressions ^ is a valid math operator, but TeXstudio treats ^ as only valid in math mode.

@sunderme
Copy link
Member

sunderme commented Mar 28, 2025

we can set it to verbatim but I believe "addplot" invents its own syntax again which uses the first argument in different contexts differently

@Axomas
Copy link
Author

Axomas commented Mar 28, 2025

Maybe a future solution:
Short-term: TeXstudio could extend its syntax definition to recognize pgfmath expressions within \addplot as a valid math mode context. This would involve updating the .cwl files (Command Word List) to include ^ as a legitimate operator in the braced argument of \addplot[] {}. This is feasible with moderate effort and would prevent the false positive highlighting of ^ as an error.
Long-term: Full support for the pgfplots- and TikZ-specific syntax would be ideal, allowing TeXstudio to accurately parse the various contexts within commands like \addplot. While this is more complex due to the diverse syntax contexts (e.g., key-value options in [] vs. mathematical expressions in {}), it would provide a robust solution for users working with advanced plotting packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants