Jlcode, greek letters, subscripts, etc

Hello everyone,

I am preparing a small book to invite future (and young) chemists to use Julia in order to solve problems in kinetics, quantum chemistry, etc. (ODEs, Catalyst, Flux, Neural ODEs, etc).
My text is written in LyX-2.3.6 and I want to use jlcode which has a very good rendering. The labels are easy to use. However, I am encountering some problems. The most urgent ones:

  1. I don’t know how to get the Greek letters,
  2. I don’t know how to get the subscripts and superscripts.

My preamble contains among other things:

\usepackage[autoload=true, linenumbers=true]{jlcode}

Although I followed the jlcode manual, compilation produces quite a few errors like:

! Package xcolor Error: Undefined color `jlrule'.
! Package xcolor Error: Undefined color `jlbackground'.
! Package xcolor Error: Undefined color `jllinenumbers'.
! Package xcolor Error: Undefined color `jlkeyword'.
! Package xcolor Error: Undefined color `jlbase'.
! Package xcolor Error: Undefined color `jlop'.
! Package xcolor Error: Undefined color `jlstrnum'.

Does anyone have a suggestion?
Thank you in advance.

I’m not sure if this can help (never used it, but recently heard very good things of it, including unicode support for LaTeX):


What do you mean by “I don’t know how to get …”? What appears when you try to compile your doc?

As for the colors, it seems (from the README) there is a specific style sheet dedicated to them?

Side note: I had found this package quite useful GitHub - m3g/jlcode_example: Example of the use of jlcode and the JuliaMono font to write Julia code in LaTeX

Thank you for your reply. As soon as I have some time, I will look at Tectonic (I must admit that I have already spent a lot of time with Listings and Minted…)


Here is an exemple of code:

\begin {jllisting}[caption={Computation of the spin-lattice relaxation time. The case of 1H NMR}, label=lis:relaxation_time] 

This program describes the NMR spin-lattice relaxation kinetics
of a 1H spin system.
A comparison is made between the analytical solution and a
numerical solution using a Tsits5() solver.

 using DifferentialEquations, Plots
#------------------------ data (S.I. units) ------------------------
 t1 = 0.92 # relaxation time (s)
 u0 = -1.0 # initial normalized value of H0
 tspan = (0.0,5.0) # time scale (s)
#------------------------ analytical solution ----------------
 equation(u,p,t) = (1/t1)*(1.0-u)

#------------------------ numerical resolution ---------------
 probleme = ODEProblem(equation,u0,tspan) 
 solution = solve(probleme, Tsit5(), reltol=1e-8, abstol=1e-8)
#------------------------ graphs -----------------------------
 plot!(solution.t, t->1.0-(2.0*exp(-t/t1))) 


So, I would like to have ¹H (instead of 1H)
Ditto for t₁ (instead of t1) and u₀

In the resolution of Schrödinger equation, I would like to obtain ψ . Indeed if I copy ψ from the REPL in the jlcode such as:

\begin {jllisting}[caption={Resolution of the 1D Schrödinger equation.}, label=lis:schrodinger_1D] 

using OrdinaryDiffEq, Plots

# Parameters (a.u. = arbitrary units) 
E = 9.90

# Conditions initiales 
x0 = [0.0]              # value of ψ à x = 0.0 (=-l/2)
dx0 = [1.0]             # valeur de dψ à x = 0.0 (=-l/2)
tspan = (-0.5, 0.5)    # x scale (a.U.) from -0.5 to +0.5

# Problem definition 
function schrodingerbox1D(ddψ,dψ,ψ,E,t)     
    ddψ .= -E * ψ 

# Passing to the solver
prob = SecondOrderODEProblem(schrodingerbox1D,dx0,x0,tspan,E) 
sol = solve(prob, DPRKN6())

plot(sol, vars=[2], linewidth=2, xaxis = "x (u.a)", 
     yaxis = "ψ(x)", framestyle = :box, 
     label = "1st pair solution") 


I obtain an error:

LaTeX command for ψ cannot be found

Here I suppose it is a problem of encoding caracters.
With Listings I could use “escape” characters such as \$\_0$ (to obtain a subscript.). With jlcode I don’t know how to proceeed with possible “escape” characters even though the manual shows plenty of nice possibilities of square root, superscript, subscript, Greek letters, special characters, etc.

I think that’s unrelated. Tectonic is a LaTeX rendering engine which claims deal with Unicode characters properly. The idea is to try it to render your minted files, for example.

Yes, I understand that Tectonic is a tool converting .tex files into .pdf files

Concerning the Greek letters, I had to change the properties of my document. Documents → Settings → Language → Others and I selected Unicode (utf8).
This is a bit strange because since version 1.5, Lyx implicitly works in Unicode utf8…

1 Like

Even more strange!
I convert my foo.lyx into foo.tex. This is a simple “export” within LyX. foo.tex is now read by Kile.
Within foo.tex (using Kile), I copy/paste the letters with their superscript or subscript, as created in the REPL.
And there, I manage to get the letters with their subscripts or exponents:

When I try to do the same operations within my foo.lyx (within LyX), I get an error. Example for t1 (with 1 in subscript):

LaTex command for '1' cannot be found (point 0x2081 of code)
Changing encoding could make things better

Why this discrepancy between foo.lyx and foo.tex?
In other words, what could I modify in LyX settings or preamble?

Thanks in advance for any help.

PS: things go better with utf8x (greek letters and subscripts = OK, but superscripts are still a problem with LyX)

The problem is resolved:
In LyX → Documents → Settings → Language → Others.
Select Unicode (XeTeX) (utf8)
Export → PDF (pdflatex)