在Julia plot标题中混合常规文本和LaTeX



尝试了所有方法,除了在我的情节中获得以下标题:"Volume in m^3 at threshold=30"。阈值应该来自一个名为threshold的变量。

using Plots
using LaTeXStrings
threshold = 30
plot(1:10)
title!("Volume in $m^3$ at threshold=$threshold")
# The following works with a hard-coded value for threshold
title!(@L_str("\textrm{Volume in }m^3\textrm{ at threshold=30}"))
# The following fails:
s = "\textrm{Volume in }m^3\textrm{ for threshold=$threshold}"
title!(@L_str(s))
Error message:
ERROR: LoadError: MethodError: no method matching 
@L_str(::LineNumberNode, ::Module, ::Symbol)
Closest candidates are:
@L_str(::LineNumberNode, ::Module, ::String) at 
/home/tarik/.julia/packages/LaTeXStrings/YQ4GM/src/LaTeXStrings.jl:68
in expression starting at REPL[25]:1

OK,通过避免L宏找到了一个解决方案,该宏除了在字符串的开头和结尾添加$符号之外似乎没有什么作用。

using Plots
using LaTeXStrings
threshold = 30
s="$\textrm{Volume in }m^3\textrm{ at threshold=$threshold}$"
plot(1:30)
title!(s)

最新更新