# Jlcode, greek letters, subscripts, etc

**URL:** <https://discourse.julialang.org/t/jlcode-greek-letters-subscripts-etc/97580>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 17, 2023, 4:26pm UTC](https://discourse.julialang.org/t/jlcode-greek-letters-subscripts-etc/97580 "2023-04-17T16:26:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![aquarelleX332](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquarellex332/32/21048_2.png) [@aquarelleX332](https://discourse.julialang.org/u/aquarelleX332)\
**Post date:** [April 17, 2023, 4:26pm UTC](https://discourse.julialang.org/t/jlcode-greek-letters-subscripts-etc/97580/1 "2023-04-17T16:26:39Z")

</div>

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](https://github.com/wg030/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:

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

```

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

```julia
! 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.  
Thierry

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [April 17, 2023, 5:36pm UTC](https://discourse.julialang.org/t/jlcode-greek-letters-subscripts-etc/97580/2 "2023-04-17T17:36:56Z")

</div>

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

> **[The Tectonic Typesetting System — The Tectonic Typesetting System](https://tectonic-typesetting.github.io/en-US/)**
>
> A modernized, complete, standalone TeX/LaTeX engine.

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [April 17, 2023, 6:41pm UTC](https://discourse.julialang.org/t/jlcode-greek-letters-subscripts-etc/97580/3 "2023-04-17T18:41:33Z")

</div>

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](https://github.com/m3g/jlcode_example)

---

<div class="post-metadata">

**Author:** ![aquarelleX332](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquarellex332/32/21048_2.png) [@aquarelleX332](https://discourse.julialang.org/u/aquarelleX332)\
**Post date:** [April 18, 2023, 8:29am UTC](https://discourse.julialang.org/t/jlcode-greek-letters-subscripts-etc/97580/4 "2023-04-18T08:29:44Z")

</div>

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…)

---

<div class="post-metadata">

**Author:** ![aquarelleX332](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquarellex332/32/21048_2.png) [@aquarelleX332](https://discourse.julialang.org/u/aquarelleX332)\
**Post date:** [April 18, 2023, 8:59am UTC](https://discourse.julialang.org/t/jlcode-greek-letters-subscripts-etc/97580/5 "2023-04-18T08:59:08Z")

</div>

@gdalle

Here is an exemple of code:

```julia
\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) 
 plot!(solution.t, t->1.0-(2.0*exp(-t/t1))) 
 savefig("relaxation_T1-1HRMN_2.pdf")

\end{jllisting}

```

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:

```julia
\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 * ψ 
end

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

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

\end{jllisting}

```

I obtain an error:

```julia
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.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [April 18, 2023, 10:05am UTC](https://discourse.julialang.org/t/jlcode-greek-letters-subscripts-etc/97580/6 "2023-04-18T10:05:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![aquarelleX332](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquarellex332/32/21048_2.png) [@aquarelleX332](https://discourse.julialang.org/u/aquarelleX332)\
**Post date:** [April 18, 2023, 10:23am UTC](https://discourse.julialang.org/t/jlcode-greek-letters-subscripts-etc/97580/7 "2023-04-18T10:23:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![aquarelleX332](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquarellex332/32/21048_2.png) [@aquarelleX332](https://discourse.julialang.org/u/aquarelleX332)\
**Post date:** [April 21, 2023, 3:58pm UTC](https://discourse.julialang.org/t/jlcode-greek-letters-subscripts-etc/97580/8 "2023-04-21T15:58:04Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![aquarelleX332](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquarellex332/32/21048_2.png) [@aquarelleX332](https://discourse.julialang.org/u/aquarelleX332)\
**Post date:** [April 22, 2023, 8:20pm UTC](https://discourse.julialang.org/t/jlcode-greek-letters-subscripts-etc/97580/9 "2023-04-22T20:20:35Z")

</div>

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:

 ![Screenshot_2](https://global.discourse-cdn.com/julialang/original/3X/3/6/36c4070a3e01d95a497dfb6ffd248e7e6f79b71b.png)  
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):

```julia
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)

---

<div class="post-metadata">

**Author:** ![aquarelleX332](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquarellex332/32/21048_2.png) [@aquarelleX332](https://discourse.julialang.org/u/aquarelleX332)\
**Post date:** [April 22, 2023, 9:26pm UTC](https://discourse.julialang.org/t/jlcode-greek-letters-subscripts-etc/97580/10 "2023-04-22T21:26:16Z")

</div>

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