texstudio
texstudio copied to clipboard
Syntax highlighting with lstlisting causes all following text to be green
Environment
- TeXstudio: < 4.8.0 -->
- Qt:
- OS:
- TeX distribution:
Expected behavior
Syntax highlighting would work for lstlisting
Actual behavior
How to reproduce
It seems to just happen with lstlisting as shown in the picture. If i select and hit Ctrl-T twice it fixes the problem, but it reoccurs frequently.
Tried with a minimal example in TeXstudio 4.8.2alpha1, not reproducible. Maybe that's already fixed between 4.8.0 and 4.8.2alpha1, or my example is too minimal.
\documentclass{article}
\usepackage{listings}
\begin{document}
content
\begin{lstlisting}[]
code code
\end{lstlisting}
abc abc
\end{document}
TeXstudio 4.8.0 (git 4.8.0) Using Qt Version 6.7.0, compiled with Qt 6.7.0 R
I can't reproduce at the moment, but I will add that this happens to me frequently as well with verbatim environments (#V classifier in cwl). Deleting some text like a character of the env name and re-typing it usually fixes it.
I would need some minimal example with confirmed behavior.
Here is a minimal example from Texstudio green lstlisting bug.tex. I have minimized it more.
\input{../Autotestcon/preamble} \RCRtrue
\input{../Autotestcon/documentclass}
\printtrue
\input{../Autotestcon/pkg}
\begin{document} \bibliographystyle{IEEEtran} % % paper title % can use linebreaks \ within to get better formatting as desired % make the title area \title{Texstudio green bug} \maketitle
\subsubsection{Introduction}
Dynamic counters are important to prevent end row or column counting.
\begin{lstlisting}[
caption={Dynamic counter of SQL pulled data column}, label=Dynamic counter of SQL data column,
linewidth=\columnwidth, breaklines=true,
language=Excel]
=UNIQUE(
FILTER(
INDIRECT("DR!" & CHAR(64 + MATCH(D3, DR!$2:$2, 0)) & "$3:" & CHAR(64 + MATCH(D3, DR!$2:$2, 0)) & ROW(INDEX(DR!$A:$A, 'Par1'!$N$1))),
(INDIRECT("DR!" & CHAR(64 + MATCH("D Component", DR!$2:$2, 0)) & "$3:" & CHAR(64 + MATCH("D Component", DR!$2:$2, 0)) & ROW(INDEX(DR!$A:$A, 'Par1'!$N$1))) <>
INDIRECT("DR!" & CHAR(64 + MATCH("Material #", DR!$2:$2, 0)) & "$3:" & CHAR(64 + MATCH("Material #", DR!$2:$2, 0)) & ROW(INDEX(DR!$A:$A,'Par1'!$N$1))))
)
)
\end{lstlisting}
Looking at Listing~\ref{Dynamic counter of SQL data column} we see a complex combination of functions that aims to filter and extract unique values from a dynamically defined range in the \texttt{DR} sheet, based on multiple conditions. Here’s a detailed breakdown of the formula.
% that's all folks
\end{document} % \fi
what about all the \input files ? Can you upload the files ? The example above is skewed by github markdown interpretation.
If the problem is in the tex editor you shouldn't need to compile, Why do you need the input files? I tested the upload . Even without the \end{document}, the problems shows up after the first lstlisting. I made my own lstlisting Language Excel, but that is allowed in the syntax so i am not sure why Texstudio is confused. So I don't see a github markdown problem.
@jeffspieg It's always recommended to mark code snippets/examples as Markdown Fenced code blocks.
Unfortunately, still not reproducible with your snippet, using TeXstudio 4.8.2alpha4. Can you check with 4.8.1 and 4.8.2alpha4? Does the wrong highlighting appears right after you opened the tex file without taking any other actions? It seems the steps to reproduce what you reported is still uncovered.
Example using lstlistings, v2
\documentclass{IEEEtran}
\usepackage{listings}
\input{../Autotestcon/preamble}
\RCRtrue
\input{../Autotestcon/documentclass}
\printtrue
\input{../Autotestcon/pkg}
\begin{document}
\bibliographystyle{IEEEtran}
%
% paper title
% can use linebreaks \ within to get better formatting as desired
% make the title area
\title{Texstudio green bug}
\maketitle
\subsubsection{Introduction}
Dynamic counters are important to prevent end row or column counting.
\begin{lstlisting}[
caption={Dynamic counter of SQL pulled data column}, label=Dynamic counter of SQL data column,
linewidth=\columnwidth, breaklines=true,
language=Excel]
=UNIQUE(
FILTER(
INDIRECT("DR!" & CHAR(64 + MATCH(D3, DR!$2:$2, 0)) & "$3:" & CHAR(64 + MATCH(D3, DR!$2:$2, 0)) & ROW(INDEX(DR!$A:$A, 'Par1'!$N$1))),
(INDIRECT("DR!" & CHAR(64 + MATCH("D Component", DR!$2:$2, 0)) & "$3:" & CHAR(64 + MATCH("D Component", DR!$2:$2, 0)) & ROW(INDEX(DR!$A:$A, 'Par1'!$N$1))) <>
INDIRECT("DR!" & CHAR(64 + MATCH("Material #", DR!$2:$2, 0)) & "$3:" & CHAR(64 + MATCH("Material #", DR!$2:$2, 0)) & ROW(INDEX(DR!$A:$A,'Par1'!$N$1))))
)
)
\end{lstlisting}
Looking at Listing~\ref{Dynamic counter of SQL data column} we see a complex combination of functions that aims to filter and extract unique values from a dynamically defined range in the \texttt{DR} sheet, based on multiple conditions. Here’s a detailed breakdown of the formula.
% that's all folks
\end{document} % \fi
txs loads cwl files depending on the \usepackage commands. Since you do not provide a complete document, default packages are loaded which does not include listings (so here your example does not make much sense unless I start to guess what packages are loaded).
Please provide and test a minimal example which really works as stand-alone example. Do not make assumptions. The example needs to be open on your side with no external inputs. txs scans all inputs and interprets usepackages and more, so that does have an influence on the outcome.
Thanks Sunderme. I see your point as txs does scan all inputs! This code can be compiled too and shows the green continuation nuisance even without the lstdefinelanguage if you'd like. No compiler errors or warnings, yet it still shows Looking at Listing... in green.
%\input{../Autotestcon/preamble} %\RCRtrue
%\input{../Autotestcon/documentclass} \documentclass[journal]{IEEEtran}
%\printtrue
%\input{../Autotestcon/pkg}
\usepackage{listings}
\lstdefinelanguage{Excel} { morekeywords={ A$1048576, B$1048576, C$1048576, D$1048576, E$1048576, F$1048576, G$1048576, H$1048576, I$1048576, J$1048576, K$1048576, L$1048576, M$1048576, N$1048576, O$1048576, P$1048576, Q$1048576, R$1048576, S$1048576, T$1048576, U$1048576, V$1048576, W$1048576, X$1048576, Y$1048576, Z$1048576, AND, ARRAYTOTEXT, AVERAGE, BYCOL, BYROW, CHAR, CHOOSE, CHOOSECOLS, CHOOSEROWS, COUNTA, COUNTIF, DROP, EXPAND, FILTER, HSTACK, IF, IFERROR, INDEX, INDEX, INDIRECT, ISBLANK, ISNUMBER, ISOMITTED, LAMBDA, LET, LOOKUP, MAKEARRAY, MAP, MATCH, MIN OR, RANDARRAY, REDUCE, ROW, SCAN, SEQUENCE, SORT, SORTBY, STOCKHISTORY, SUM, TAKE, TEXT, TEXTJOIN TEXTAFTER, TEXTBEFORE, TEXTSPLIT, TOCOL, TOROW, UNIQUE, VALUETOTEXT, VLOOKUP, VSTACK, WRAPCOLS, WRAPROWS, XLOOKUP XMATCH }, sensitive=false, morecomment=[l]{//}, morestring=[b]", }
\begin{document}
\title{Texstudio green bug}
\maketitle
\subsubsection{Introduction}
Dynamic counters are important to prevent end row or column counting.
\begin{lstlisting}[
caption={Dynamic counter of SQL pulled data column}, label=Dynamic counter of SQL data column,
linewidth=\columnwidth, breaklines=true,
language=Excel]
=UNIQUE(
FILTER(
INDIRECT("DR!" & CHAR(64 + MATCH(D3, DR!$2:$2, 0)) & "$3:" & CHAR(64 + MATCH(D3, DR!$2:$2, 0)) & ROW(INDEX(DR!$A:$A, 'Par1'!$N$1))),
(INDIRECT("DR!" & CHAR(64 + MATCH("D Component", DR!$2:$2, 0)) & "$3:" & CHAR(64 + MATCH("D Component", DR!$2:$2, 0)) & ROW(INDEX(DR!$A:$A, 'Par1'!$N$1))) <>
INDIRECT("DR!" & CHAR(64 + MATCH("Material #", DR!$2:$2, 0)) & "$3:" & CHAR(64 + MATCH("Material #", DR!$2:$2, 0)) & ROW(INDEX(DR!$A:$A,'Par1'!$N$1))))
)
)
\end{lstlisting}
Looking at Listing~\ref{Dynamic counter of SQL data column} we see a complex combination of functions that aims to filter and extract unique values from a dynamically defined range in the \texttt{DR} sheet, based on multiple conditions. Here’s a detailed breakdown of the formula.
% that's all folks
\end{document} % \fi
just by entering or reloading the code, I see no issue with the highlighting. I assume that begin{lstlisting... ènd{lstlisting}`is the region of interest.
For me this code has the text the wrong color and even the \end{document} is green. I have had this problem for multiple versions of Texstudio and it corrects if I select the text Comment (Ctrl-T) and Uncomment (Ctrl-T), but reoccurs in multiple places and when closing and opening the file again. Very annoying when it occurs near the beginning of a long file and then everything is green thereafter and multiple lstlisting(s) reinitiate the green even if I correct the first instance.
the task at hand is to reproduce the issue.
so
- you have only the test document open, no other open files
- no changed configuration
- when you start txs and the session with the single test file is restored, the syntax highlighting is as you show it ?
- Yes. 2. Yes. 3. No.
When I restarted on this file the problem went away. But going back to the file where I took this code the problem still exists for 1-3. I will have to make a better example.
While working on a better example I found the following:
When I comment out \input{../Autotestcon/pkg}, the Green runaway font color change in Texstudio goes away.
\input{../Autotestcon/preamble}
\input{../Autotestcon/documentclass}
%\input{../Autotestcon/pkg}
%SUCCESS here in editor but can't compile without pkg.
When i uncomment it then it comes back.
\input{../Autotestcon/preamble} \input{../Autotestcon/documentclass} \input{../Autotestcon/pkg} %FAILURE here with Green runaway in editor but no errors when compiling.
If I put everything inside pkg into a comment and save the file, the Green runaway still occurs! Why is that ? It is the same as an empty file? Did the same thing with #iffalse ... #\fi around all contents and still has Green runaway.
I changed pkg to \input{../Autotestcon/pkg2} then back to pkg and it crashed. Note pkg2 did not exist, but Texstudio crashes going back to the original similar to this backtrace:
Here's the back trace: unknown at 7ff7fbbf30f0 (TXS-Version 4.8.0 R ) [bt] 00007ff7fbb3d4a5 q+3585657 [bt] 00007ff7fbb3c6b7 q+3582091 [bt] 00007ff7fba539e9 q+2628541 [bt] 000001d8190d89f0 ??? error: 126
Saved pkg to pkgGrreen and then while changing \input{../Autotestcon/pkg} to \input{../Autotestcon/pkgGreen} just typing in Texstudio the application crashes. FYI I have never seen 4.8.0 crash before so I think we are getting closer:
Texstudio is getting very adverserial the closer I get to the cause. I don't want to give the full pkg file but wanted to divide and conquer the location that is problematic. Unfortunately I found even with no contents the file is a problem.
you can send larger test cases directly to me for debug.([email protected]) They are handled confidentially.
not been able to reproduce a crash was fixed
This is still a problem although I found a work around. Here is a self-contained .tex tile that will show you the problem after the second listing:
%\input{../Autotestcon/preamble} \newif\ifRCR \newif\ifprint \newif\ifTEXold \printfalse \RCRtrue
%\input{../Autotestcon/documentclass} \documentclass[journal]{IEEEtran}
\printtrue
%\input{../Autotestcon/pkgGreen} \usepackage{listings} %\lstset{basicstyle=\small\ttfamily,columns=fullflexible} %\lstset{columns=fullflexible,frame=single,captionpos=b} %\lstdefinestyle{sharpc}{language=[Sharp]C, frame=lr, rulecolor=\color{blue!80!black}} %\lstset{columns=fullflexible,captionpos=b,showstringspaces=false,basicstyle=\ttfamily}
\lstdefinelanguage{Excel} { morekeywords={ A$1048576, B$1048576, C$1048576, D$1048576, E$1048576, F$1048576, G$1048576, H$1048576, I$1048576, J$1048576, K$1048576, L$1048576, M$1048576, N$1048576, O$1048576, P$1048576, Q$1048576, R$1048576, S$1048576, T$1048576, U$1048576, V$1048576, W$1048576, X$1048576, Y$1048576, Z$1048576, AND, ARRAYTOTEXT, AVERAGE, BYCOL, BYROW, CHAR, CHOOSE, CHOOSECOLS, CHOOSEROWS, COUNTA, COUNTIF, DROP, EXPAND, FILTER, HSTACK, IF, IFERROR, INDEX, INDEX, INDIRECT, ISBLANK, ISNUMBER, ISOMITTED, LAMBDA, LET, LOOKUP, MAKEARRAY, MAP, MATCH, MIN OR, RANDARRAY, REDUCE, ROW, SCAN, SEQUENCE, SORT, SORTBY, STOCKHISTORY, SUM, TAKE, TEXT, TEXTJOIN TEXTAFTER, TEXTBEFORE, TEXTSPLIT, TOCOL, TOROW, UNIQUE, VALUETOTEXT, VLOOKUP, VSTACK, WRAPCOLS, WRAPROWS, XLOOKUP XMATCH }, sensitive=false, morecomment=[l]{//}, morestring=[b]", }
\lstset{columns=fullflexible,captionpos=b,showstringspaces=false,basicstyle=\ttfamily\small, numbers=left, numberstyle=\tiny, stepnumber=5, numberfirstline=false, firstnumber=2, numbersep=5pt, breaklines=true}
\begin{document}
\title{Texstudio green bug}
\maketitle
\subsubsection{Introduction}
Dynamic counters are important to prevent end row or column counting.
\begin{lstlisting}[
caption={Dynamic counter of SQL pulled data column}, label=Dynamic counter of SQL data column,
linewidth=\columnwidth, breaklines=true,
language=Excel]
=UNIQUE(
FILTER(
INDIRECT("DR!" & CHAR(64 + MATCH(D3, DR!$2:$2, 0)) & "$3:" & CHAR(64 + MATCH(D3, DR!$2:$2, 0)) & ROW(INDEX(DR!$A:$A, 'Par1'!$N$1))),
(INDIRECT("DR!" & CHAR(64 + MATCH("D Component", DR!$2:$2, 0)) & "$3:" & CHAR(64 + MATCH("D Component", DR!$2:$2, 0)) & ROW(INDEX(DR!$A:$A, 'Par1'!$N$1))) <>
INDIRECT("DR!" & CHAR(64 + MATCH("Material #", DR!$2:$2, 0)) & "$3:" & CHAR(64 + MATCH("Material #", DR!$2:$2, 0)) & ROW(INDEX(DR!$A:$A,'Par1'!$N$1))))))
\end{lstlisting}
By adding a blank line before \begin{verbatim}\end{lstlisting}\end{verbatim} then I can get rid of the green text.
\begin{lstlisting}[caption={Conditional formatting rule for pareto tables}, label=Cfrules1, linewidth=\columnwidth, breaklines=true, language=Excel]
=OR(W3<=20, AND(W2<20, W3>=20)):
with W helper column
=SUM(V$3:V3).
Better to use a dynamic array in the helper column:
=LET(
firstBlank, MATCH(TRUE, INDEX(U3:U100="",), 0),
adjustedRange, SEQUENCE(firstBlank - 1, 1, 3),
SCAN(0, INDEX(V:V, adjustedRange), LAMBDA(a,b, a + b))
=LET(
firstBlank, MATCH(TRUE, INDEX(U3:U100="",), 0),
adjustedRange, SEQUENCE(firstBlank - 1, 1, 3),
SCAN(0, INDEX(V:V, adjustedRange), LAMBDA(a,b, a + b))
\end{lstlisting}
Looking at Listing~\ref{Dynamic counter of SQL data column} we see a complex combination of functions that aims to filter and extract unique values from a dynamically defined range in the \texttt{DR} sheet, based on multiple conditions. Here’s a detailed breakdown of the formula.
\end{document}
Reopen issue #3762 as I added a new example
On Sat, Oct 12, 2024 at 5:48 AM sunderme @.***> wrote:
not been able to reproduce a crash was fixed
— Reply to this email directly, view it on GitHub https://github.com/texstudio-org/texstudio/issues/3762#issuecomment-2408535006, or unsubscribe https://github.com/notifications/unsubscribe-auth/BHZRTKMFEZQLCEYUJENLQHTZ3EECDAVCNFSM6AAAAABMOHJQRGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMBYGUZTKMBQGY . You are receiving this because you were mentioned.Message ID: @.***>
How do I see an issue ?
%\input{../Autotestcon/preamble} \newif\ifRCR \newif\ifprint \newif\ifTEXold \printfalse \RCRtrue
%\input{../Autotestcon/documentclass} \documentclass[journal]{IEEEtran}
\printtrue
%\input{../Autotestcon/pkgGreen} \usepackage{listings} %\lstset{basicstyle=\small\ttfamily,columns=fullflexible} %\lstset{columns=fullflexible,frame=single,captionpos=b} %\lstdefinestyle{sharpc}{language=[Sharp]C, frame=lr, rulecolor=\color{blue!80!black}} %\lstset{columns=fullflexible,captionpos=b,showstringspaces=false,basicstyle=\ttfamily}
\lstdefinelanguage{Excel} { morekeywords={ A$1048576, B$1048576, C$1048576, D$1048576, E$1048576, F$1048576, G$1048576, H$1048576, I$1048576, J$1048576, K$1048576, L$1048576, M$1048576, N$1048576, O$1048576, P$1048576, Q$1048576, R$1048576, S$1048576, T$1048576, U$1048576, V$1048576, W$1048576, X$1048576, Y$1048576, Z$1048576, AND, ARRAYTOTEXT, AVERAGE, BYCOL, BYROW, CHAR, CHOOSE, CHOOSECOLS, CHOOSEROWS, COUNTA, COUNTIF, DROP, EXPAND, FILTER, HSTACK, IF, IFERROR, INDEX, INDEX, INDIRECT, ISBLANK, ISNUMBER, ISOMITTED, LAMBDA, LET, LOOKUP, MAKEARRAY, MAP, MATCH, MIN OR, RANDARRAY, REDUCE, ROW, SCAN, SEQUENCE, SORT, SORTBY, STOCKHISTORY, SUM, TAKE, TEXT, TEXTJOIN TEXTAFTER, TEXTBEFORE, TEXTSPLIT, TOCOL, TOROW, UNIQUE, VALUETOTEXT, VLOOKUP, VSTACK, WRAPCOLS, WRAPROWS, XLOOKUP XMATCH }, sensitive=false, morecomment=[l]{//}, morestring=[b]", }
\lstset{columns=fullflexible,captionpos=b,showstringspaces=false,basicstyle=\ttfamily\small, numbers=left, numberstyle=\tiny, stepnumber=5, numberfirstline=false, firstnumber=2, numbersep=5pt, breaklines=true}
\begin{document}
\title{Texstudio green bug} \maketitle
\subsubsection{Introduction} Dynamic counters are important to prevent end row or column counting. \begin{lstlisting}[ caption={Dynamic counter of SQL pulled data column}, label=Dynamic counter of SQL data column, linewidth=\columnwidth, breaklines=true, language=Excel] =UNIQUE( FILTER( INDIRECT("DR!" & CHAR(64 + MATCH(D3, DR!$2:$2, 0)) & "$3:" & CHAR(64 + MATCH(D3, DR!$2:$2, 0)) & ROW(INDEX(DR!$A:$A, 'Par1'!$N$1))), (INDIRECT("DR!" & CHAR(64 + MATCH("D Component", DR!$2:$2, 0)) & "$3:" & CHAR(64 + MATCH("D Component", DR!$2:$2, 0)) & ROW(INDEX(DR!$A:$A, 'Par1'!$N$1))) <> INDIRECT("DR!" & CHAR(64 + MATCH("Material #", DR!$2:$2, 0)) & "$3:" & CHAR(64 + MATCH("Material #", DR!$2:$2, 0)) & ROW(INDEX(DR!$A:$A,'Par1'!$N$1)))))) \end{lstlisting} By adding a blank line before \begin{verbatim}\end{lstlisting}\end{verbatim} then I can get rid of the green text. \begin{lstlisting}[caption={Conditional formatting rule for pareto tables}, label=Cfrules1, linewidth=\columnwidth, breaklines=true, language=Excel] =OR(W3<=20, AND(W2<20, W3>=20)): with W helper column =SUM(V$3:V3). Better to use a dynamic array in the helper column: =LET( firstBlank, MATCH(TRUE, INDEX(U3:U100="",), 0), adjustedRange, SEQUENCE(firstBlank - 1, 1, 3), SCAN(0, INDEX(V:V, adjustedRange), LAMBDA(a,b, a + b)) =LET( firstBlank, MATCH(TRUE, INDEX(U3:U100="",), 0), adjustedRange, SEQUENCE(firstBlank - 1, 1, 3), SCAN(0, INDEX(V:V, adjustedRange), LAMBDA(a,b, a + b)) \end{lstlisting} Looking at Listing~\ref{Dynamic counter of SQL data column} we see a complex combination of functions that aims to filter and extract unique values from a dynamically defined range in the \texttt{DR} sheet, based on multiple conditions. Here’s a detailed breakdown of the formula. % that's all folks \end{document} % \fi
On Tue, Oct 22, 2024 at 9:47 AM sunderme @.***> wrote:
How do I see an issue ? grafik.png (view on web) https://github.com/user-attachments/assets/e4b0902e-9597-45fa-9bb3-3995adfaec37
— Reply to this email directly, view it on GitHub https://github.com/texstudio-org/texstudio/issues/3762#issuecomment-2429645565, or unsubscribe https://github.com/notifications/unsubscribe-auth/BHZRTKMZRLN5XGDB62JHU2LZ4ZXQZAVCNFSM6AAAAABMOHJQRGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMRZGY2DKNJWGU . You are receiving this because you were mentioned.Message ID: @.***>
Just put the tex i sent into texstudio. the bottom half stays green when it shouldn't
On Tue, Oct 22, 2024 at 9:45 AM sunderme @.***> wrote:
? grafik.png (view on web) https://github.com/user-attachments/assets/f75e1d84-3e7e-41b3-8c72-d938c26c5976
— Reply to this email directly, view it on GitHub https://github.com/texstudio-org/texstudio/issues/3762#issuecomment-2429642077, or unsubscribe https://github.com/notifications/unsubscribe-auth/BHZRTKOSGOQUPKMUXJOLRPDZ4ZXLDAVCNFSM6AAAAABMOHJQRGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMRZGY2DEMBXG4 . You are receiving this because you were mentioned.Message ID: @.***>
can you remove the commented out inputs ? Do you have any cwls activated in the options ? Can anybody else reproduce the issue ?
That's what I see:
Win10/MikTex TeXstudio 4.8.5 (git 4.8.5alpha1-29-gb7ef6508a) Using Qt Version 6.7.2, compiled with Qt 6.7.2 R
I see Green below the lstlisting that should be white:
If I add a CR just before the \end{lstlisting} then the subsequent text turns white as expected. Removing comments will have no effect on this problem.
CWLs not really using them. Maybe I have a Macro or two with a text recognition trigger. I think lstlisting is not commonly used package and someone missed something in recognizing it. I am not sure why I am the only one able to reproduce it, but I concede I am still using 4.8.0.
Look it becomes white by adding the CR!
Do you follow the same procedure as I do? Start txs (best without any previous documents), open a new editor and paste the code from here, that you have posted before. Then, what is the coloring?