Skip to content
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

Plenty of error messages involving xcolor #49

Open
andreasvarga opened this issue Oct 28, 2022 · 7 comments
Open

Plenty of error messages involving xcolor #49

andreasvarga opened this issue Oct 28, 2022 · 7 comments

Comments

@andreasvarga
Copy link

I was not able to run Latex using TexStudio on the following text file without obtaining plenty of error messages involving xcolor. All messages resemble the following one:
Package xcolor Error: Undefined color jlbase'. ...ultDetectionTools, DescriptorSystems, Test`

Here is the contents of the text file:

\documentclass[11pt,a4paper]{article}

% Code blocks definitions: Julia style
% Using https://github.com/wg030/jlcode
% Download the jlcode.sty from that repository 

\usepackage{listings}
\makeatletter
%\usepackage[theme=default]{jlcode}
\usepackage[autoload=true]{jlcode}
%\usepackage{jlcode}
\lstset{%
	language         = Julia,%
	basicstyle       = \small\ttfamily\bfseries,%
	keywordstyle     = \small\bfseries\color{blue},%
	stringstyle      = \small\ttfamily\bfseries,%
    backgroundcolor = \color{white},%
    commentstyle=\small\ttfamily\slshape\bfseries\color{magenta},%
	showstringspaces = false
}
\begin{document}


\begin{jllisting}[frame=lines]
using FaultDetectionTools, DescriptorSystems, Test

# Example 5.4 - Solution of an EFDP
println("Example 5.4")

# define s as an improper transfer function
s = rtf('s');
# define Gu(s), Gd(s), Gf(s)
Gu = [(s+1)/(s-2); (s+2)/(s-3)];     # enter Gu(s)
Gd = [(s-1)/(s+2); 0];               # enter Gd(s)
Gf = [(s+1)/(s-2) 0; (s+2)/(s-3) 1]; # enter Gf(s)
p = 2; mu = 1; md = 1; mf = 2;       # set dimensions

# compute a left nullspace basis Q of [Gu Gd; I 0]
Q1 = glnull(dss([Gu Gd;eye(mu,mu+md)]))[1];

# compute Rf1 = Q1[Gf;0]
Rf1 = gir(Q1*dss([Gf;zeros(mu,mf)]));

# check solvability using a random frequency
if minimum(abs.(evalfr(Rf1,rand()))) > 0.01
   # compute a stable left coprime factorization [Q1 Rf1]=inv(Q3)*[Q,Rf]
   # enforce stability degree -3
   Q_Rf, Q3 = glcf([Q1 Rf1];sdeg = -3);
   # extract Q and Rf
   Q = Q_Rf[:,1:p+mu]; Rf = Q_Rf[:,p+mu+1:end]; 
   scale = evalfr(Rf[1,1],Inf)[1,1]
   Q = Q/scale; Rf = Rf/scale;
   @test gpole(Q) ≈ [-3] && gpole(Rf) ≈ [-3] && fditspec_(Rf) == Bool[1 1] && 
   iszero(Rf - Q*dss([Gf;zeros(mu,mf)]),atol=1.e-7)  && 
   iszero(Q*dss([Gu Gd;eye(mu,mu+md)]),atol=1.e-7)
   # normalize Q and Rf to match example
   println(" Q = $(dss2rm(Q,atol=1.e-7))")
   println(" Rf = $(dss2rm(Rf,atol=1.e-7))")
else
   @info "No solution exists"
end

\end{jllisting}
	
\end{document}

I tried all three alternative ways to load jlcode.sty. The output file looks approximately as expected
Screenshot 2022-10-28 175812

I wonder what I am doing wrong.

@wg030
Copy link
Owner

wg030 commented Oct 29, 2022

It looks like the error comes from overwriting the basicstyle property here.
The way you do it now prevents the package from loading the defined colors (see line 526 of jlcode.sty).
If you want different colors than those avaiable in the package I would recommend you to modify the package file and add your own color sheme there analogously to the exsisting ones instead of using lstset

@wg030 wg030 mentioned this issue Oct 29, 2022
@andreasvarga
Copy link
Author

andreasvarga commented Oct 29, 2022

My understanding is that \lstset is a convenient way to modify some predefined language settings for generating a code listing in that language. So, this feature would be desirable to work also with jlcode.sty. For my book project, I actually don't need colors (perhaps gray or darkgray for comments, but slanted would also do the job), but even in the absence of colors the error messages are issued. Modifying the style file for this purpose (as you propose), would certainly be possible, but I wonder if this is desirable in the perspective that Julia will become part of standard selected languages in listings.

Just for fun, I selected Matlab as language, and I was able to generate an acceptable output for me with the following commands

\lstloadlanguages{Matlab}
\lstset{%
literate= {≈}{{$\approx$}}1,
basicstyle=\small\ttfamily\bfseries,
morecomment=[l]{\#},
commentstyle=\small\ttfamily\slshape\mdseries\color{magenta},
mathescape=true}

Regarding the \approx error #48, if I switch to

\usepackage[autoload=false]{jlcode}

then the \approx sign is not listed and error messages are issued. However, with the above setting for Matlab, it works as expected also for Julia!

@wg030
Copy link
Owner

wg030 commented Nov 3, 2022

My understanding is that \lstset is a convenient way to modify some predefined language settings for generating a code listing in that language. So, this feature would be desirable to work also with jlcode.sty.

Well, your understanding of \lstset is correct as far as the listings package itself is considered. However, the jlcode package is supposed to be more than just a pure language definition for Julia that can be applied with listings. It has rather become kind of an independet package that does lots of things in the background by using listings. Especially, how the code is displayed is supposed to be done by choosing a suitable complete theme rather than setting all properties on your own with \lstset. The main reason for this design is that there are some kind of hacks applied to make colors and symbols to be displayed as correctly as possible.

For example, if you did it like this

Just for fun, I selected Matlab as language, and I was able to generate an acceptable output for me with the following commands

\lstloadlanguages{Matlab}
\lstset{%
literate= {≈}{{$\approx$}}1,
basicstyle=\small\ttfamily\bfseries,
morecomment=[l]{\#},
commentstyle=\small\ttfamily\slshape\mdseries\color{magenta},
mathescape=true}

Regarding the \approx error #48, if I switch to

\usepackage[autoload=false]{jlcode}

then the \approx sign is not listed and error messages are issued. However, with the above setting for Matlab, it works as expected also for Julia!

you might be ok with the ≈ symbol, but all other special symbols you use will cause you trouble because you would essentially need to define them all with the literate= in \lstset. Obviously, this is not what most people (if any) would really want. People want a quick way to get their codes displayed as easy as possible.
Having said this, most people just want to write

\documentclass[11pt,a4paper]{article}

% Code blocks definitions: Julia style
% Using https://github.com/wg030/jlcode
% Download the jlcode.sty from that repository 

\usepackage[theme=grayscale-plain]{jlcode}
\begin{document}

\begin{jllisting}
using FaultDetectionTools, DescriptorSystems, Test

# Example 5.4 - Solution of an EFDP
println("Example 5.4")

# define s as an improper transfer function
s = rtf('s');
# define Gu(s), Gd(s), Gf(s)
Gu = [(s+1)/(s-2); (s+2)/(s-3)];     # enter Gu(s)
Gd = [(s-1)/(s+2); 0];               # enter Gd(s)
Gf = [(s+1)/(s-2) 0; (s+2)/(s-3) 1]; # enter Gf(s)
p = 2; mu = 1; md = 1; mf = 2;       # set dimensions

# compute a left nullspace basis Q of [Gu Gd; I 0]
Q1 = glnull(dss([Gu Gd;eye(mu,mu+md)]))[1];

# compute Rf1 = Q1[Gf;0]
Rf1 = gir(Q1*dss([Gf;zeros(mu,mf)]));

# check solvability using a random frequency
if minimum(abs.(evalfr(Rf1,rand()))) > 0.01
   # compute a stable left coprime factorization [Q1 Rf1]=inv(Q3)*[Q,Rf]
   # enforce stability degree -3
   Q_Rf, Q3 = glcf([Q1 Rf1];sdeg = -3);
   # extract Q and Rf
   Q = Q_Rf[:,1:p+mu]; Rf = Q_Rf[:,p+mu+1:end]; 
   scale = evalfr(Rf[1,1],Inf)[1,1]
   Q = Q/scale; Rf = Rf/scale;
   @test gpole(Q) ≈ [-3] && gpole(Rf) ≈ [-3] && fditspec_(Rf) == Bool[1 1] && 
   iszero(Rf - Q*dss([Gf;zeros(mu,mf)]),atol=1.e-7)  && 
   iszero(Q*dss([Gu Gd;eye(mu,mu+md)]),atol=1.e-7)
   # normalize Q and Rf to match example
   println(" Q = $(dss2rm(Q,atol=1.e-7))")
   println(" Rf = $(dss2rm(Rf,atol=1.e-7))")
else
   @info "No solution exists"
end
\end{jllisting}
	
\end{document}

and get a nice smooth output of their code and this is exactly what his package does and is actually supposed to do.

@andreasvarga
Copy link
Author

Thanks for your time and I fully agree with your points. However, for my purposes the output of the above code is not satisfactory and therefore I need more flexibility to modify a selected theme (e.g., I need boldface fonts and dark code text to make the code more visible). Since in the meantime I found an alternative solution which suits my goals, I will close all issues which I opened.

@wg030
Copy link
Owner

wg030 commented Nov 4, 2022

Thanks for your time and I fully agree with your points. However, for my purposes the output of the above code is not satisfactory and therefore I need more flexibility to modify a selected theme (e.g., I need boldface fonts and dark code text to make the code more visible).

Well, if the standard themes are not sufficiently satisfying for your needs, then yes, as of now, you would need to make some efforts by modifying the jlcode.sty file yourself if you want to go with this package.
If you did that or are about to do that, then feel free to open a PR that includes your new style. I think the whole community especially me myself would highly appreciate that.

I might consider to add a few more new options myself in the future and/or at least give a hint for that kind of error in the manual. Hence I will reopen this issue in order to be reminded of doing so.

@wg030 wg030 reopened this Nov 4, 2022
@axsk
Copy link

axsk commented Oct 4, 2023

I also have some (168) errors using this .sty:
Package xcolor Error: Undefined color jlrule'.`
I do not modify colors or anything in any way. I only usepackage xcolors and listings beforehand for other uses.

@wg030
Copy link
Owner

wg030 commented Oct 4, 2023

I also have some (168) errors using this .sty:
Package xcolor Error: Undefined color jlrule'.`
I do not modify colors or anything in any way. I only usepackage xcolors and listings beforehand for other uses.

Well, that sounds like a similar problem.
Could you please create a minimal working example so that I can reproduce the error on my machine?

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

No branches or pull requests

3 participants