我在尝试代码在 LyX 文档中插入 Julia 代码。以下是基本程序的 .tex 文件示例:
%% LyX 2.3.6 created this file. For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[french]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\newcommand{\noun}[1]{\textsc{#1}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\date{}
\usepackage[autoload=true]{jlcode}
\makeatother
\usepackage{babel}
\makeatletter
\addto\extrasfrench{%
\providecommand{\og}{\leavevmode\flqq~}%
\providecommand{\fg}{\ifdim\lastskip>\z@\unskip\fi~\frqq}%
}
\makeatother
\begin{document}
\title{\textbf{\noun{Using jlcode}}}
\maketitle
Here is an example of code:
\begin{jllisting}[language=julia, style=jlcodestyle]
"""
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.
"""
#Greek letters are imported from Julia REPL: α, β, γ, δ, ε, ...
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}
\end{document}
最初我无法获得希腊字母。我通过更改 Lyx 中的设置成功了:文档 --> 设置 --> 语言 --> 其他。我选择了 Unicode (utf8)。结果如下图所示:
我的问题是:如何获取上标、下标和其他可能的特殊数学字符?例如,1H 应该以 1 的形式出现在上标中(因为它代表氢原子)。同样,在 t1 中,1 应该作为下标出现。
虽然我知道 TeX 的方法(例如 t$_1$),但使用 jlcode 时,我不知道该怎么做。你能指导我吗,因为jlcode 手册虽然给出了一个很好的列表却没有提供获取它们的方法?
答案1
在 Lyx 中,文档 --> 设置 --> 语言 --> 其他。选择Unicode(XeTeX)(utf8). 符号、下标、上标可以从 Julia 的 REPL 中复制/粘贴。