#\lstinputlisting colours not showing up for special letters!

1 messages · Page 1 of 1 (latest)

grave wolf
#

I have colours set my a neat display of code, however characters like čšž appear in normal black instead of being tidy like other letters.

#

they should be green

grave wolf
#

like that

#

I've tried literates, inputencoding and charencoding.

tawny tartan
#

Show us what you've done

#

I cannot replicate your problem

pearl pilotBOT
#
\Google%just a theme
\lstset{
    literate=%
    {č}{{\v{c}}}1
    {š}{{\v{s}}}1
    {ž}{{\v{z}}}1,
    language=C
}

\begin{lstlisting}
printf("csz");
printf("čšž");
getchar();
\end{lstlisting}
grave wolf
#

@tawny tartan does it work for you if you include it from a file

grave wolf
#

using \lstinputlisting[]{file.c}

#

I've tried putting the literates inside \lstdefinestyle and \lstset, but nothing worked

tawny tartan
#
\begin{filecontents*}{file.c}
printf("csz");
printf("čšž");
getchar();
\end{filecontents*}

\Google%just a theme
\lstset{
    literate=%
    {č}{{\v{c}}}1
    {š}{{\v{s}}}1
    {ž}{{\v{z}}}1,
    language=C
}

\lstinputlisting{file.c}
pearl pilotBOT
tawny tartan
#

Again, I cannot recreate the problem you are encountering.

grave wolf
#

then it must be the theme, because I'm using \lstdefinestyle and you're using some other Google theme I do not know how to set

tawny tartan
#

theme? that only deals with colours.

#

Here it is without \Google:

grave wolf
#

yeah, isn't this the point of the problem?

tawny tartan
#
\begin{filecontents*}{file.c}
printf("csz");
printf("čšž");
getchar();
\end{filecontents*}

\lstset{
    literate=%
    {č}{{\v{c}}}1
    {š}{{\v{s}}}1
    {ž}{{\v{z}}}1,
    language=C
}

\lstinputlisting{file.c}
pearl pilotBOT
tawny tartan
#

(this is the only reason why i used a light-coloured theme named Google)

#

but anyway the colours/themes aren't the problem in the context of highlighting the strings

grave wolf
#
\lstdefinestyle{code}{
    backgroundcolor = \color{orange},
    stringstyle = \color{teal},
    basicstyle = \ttfamily,
    captionpos = b,
    language = C,
}

\lstset{style = code}

let's say this would be example style, which doesn't work

#
\lstinputlisting[caption = Caption]{Example.c}
``` this is how I'd put it in the document
tawny tartan
#

I thought this was about čšž not being highlighted properly, where everything else was being correctly highlighted?

grave wolf
#

it is.

#

what do are you thinking it would be

tawny tartan
#

I'm seriously struggling to recreate the problem.

grave wolf
#

can you try in lualatex, because that's what I'm using

#

can you send your files so I can see if it would work for me

tawny tartan
#

(minus the \Google of course.)

#

I'll write it again for you

#
\begin{filecontents*}{file.c}
printf("csz");
printf("čšž");
getchar();
\end{filecontents*}

\lstset{
    literate=%
    {č}{{\v{c}}}1
    {š}{{\v{s}}}1
    {ž}{{\v{z}}}1,
    language=C,
    stringstyle=\color{magenta}
}

\lstinputlisting{file.c}
#

and this is what you should get.

grave wolf
#

lstset is in the preamble, right?

tawny tartan
#

No, all of it goes inside document

#

like this

grave wolf
#

well I have \lstset{style = code} in the preamble and the styling works as shown in my problem

#

do you include any packages? I cannot find any that would be connected to listings

tawny tartan
#

\lstset and \lstinputlisting are provided by listings and to use colours I loaded xcolor

#

Nothing else

grave wolf
#

oh I found it, it doesn't load unless \usepackage[most]{tcolorbox} is loaded

#

otherwise it says ! Undefined control sequence. \lstset

#

in my main document, I use tcolorbox for some other boxes that's why I didn't include listings

tawny tartan
#

lstset is defined in listings

#

I presume you needed something like \tcbuselibrary{listings}

grave wolf
#

how do you see in your files if it's correctly highlighted? with the code you provided, there's no theme and so it's just black and white serif font

tawny tartan
#

stringstyle=\color{magenta} key-value pair should highlight the strings as desired.

#

In case you don't believe me:

tawny tartan
grave wolf
#

but I don't

tawny tartan
#

I don't know what else I can do at this point, seems to be new details popping up with every exchange

#

I'm sure a more experienced TeXnician will help you out, good luck!

grave wolf
#

also I didn't know it could make a c file on its own like that

grave wolf
#

I tried with texworks and it appears to work now, though it has trouble making the entire document that I have the rest of stuff in

tawny tartan
#

I am familiar with vim

grave wolf
#

which editor do you use then

tawny tartan
#

VSCode most often, a heavily-modded version of TeXStudio second