Giter Club home page Giter Club logo

Comments (7)

wg030 avatar wg030 commented on June 9, 2024

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

from jlcode.

andreasvarga avatar andreasvarga commented on June 9, 2024

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!

from jlcode.

wg030 avatar wg030 commented on June 9, 2024

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.

from jlcode.

andreasvarga avatar andreasvarga commented on June 9, 2024

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.

from jlcode.

wg030 avatar wg030 commented on June 9, 2024

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.

from jlcode.

axsk avatar axsk commented on June 9, 2024

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.

from jlcode.

wg030 avatar wg030 commented on June 9, 2024

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?

from jlcode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.