MathTeXEngine.jl
MathTeXEngine.jl copied to clipboard
Unexpected error while parsing `\boldsymbol`
julia> generate_tex_elements(L"\boldsymbol{\nabla}")
ERROR: TeXParseError: unexpected error while parsing
at position 12 (string index 12)
\boldsymbol{\nabla}
^
Stack before
[1] TeXExpr :expr
Stacktrace:
[1] texparse(data::String; showdebug::Bool)
@ MathTeXEngine ~/.julia/packages/MathTeXEngine/na9MW/src/parser/parser.jl:303
[2] texparse
@ ~/.julia/packages/MathTeXEngine/na9MW/src/parser/parser.jl:287 [inlined]
[3] _broadcast_getindex_evalf
@ ./broadcast.jl:683 [inlined]
[4] _broadcast_getindex
@ ./broadcast.jl:656 [inlined]
[5] _getindex
@ ./broadcast.jl:679 [inlined]
[6] _broadcast_getindex
@ ./broadcast.jl:655 [inlined]
[7] getindex
@ ./broadcast.jl:610 [inlined]
[8] copy
@ ./broadcast.jl:912 [inlined]
[9] materialize
@ ./broadcast.jl:873 [inlined]
[10] generate_tex_elements(str::LaTeXStrings.LaTeXString, font_family::MathTeXEngine.FontFamily)
@ MathTeXEngine ~/.julia/packages/MathTeXEngine/na9MW/src/engine/layout.jl:301
[11] generate_tex_elements(str::LaTeXStrings.LaTeXString)
@ MathTeXEngine ~/.julia/packages/MathTeXEngine/na9MW/src/engine/layout.jl:295
[12] top-level scope
@ REPL[6]:1
caused by: TeXParseError: unsupported command \boldsymbol
at position 12 (string index 12)
\boldsymbol{\nabla}
^
Stack before
[1] TeXExpr :expr
Stacktrace:
[1] _end_command_builder!(stack::DataStructures.Stack{Any}, p::Int64, data::String)
@ MathTeXEngine ~/.julia/packages/MathTeXEngine/na9MW/src/parser/parser.jl:251
[2] macro expansion
@ ~/.julia/packages/MathTeXEngine/na9MW/src/parser/parser.jl:274 [inlined]
[3] macro expansion
@ ~/.julia/packages/Automa/5enCH/src/codegen.jl:150 [inlined]
[4] texparse(data::String; showdebug::Bool)
@ MathTeXEngine ~/.julia/packages/MathTeXEngine/na9MW/src/parser/parser.jl:301
[5] texparse
@ ~/.julia/packages/MathTeXEngine/na9MW/src/parser/parser.jl:287 [inlined]
[6] _broadcast_getindex_evalf
@ ./broadcast.jl:683 [inlined]
[7] _broadcast_getindex
@ ./broadcast.jl:656 [inlined]
[8] _getindex
@ ./broadcast.jl:679 [inlined]
[9] _broadcast_getindex
@ ./broadcast.jl:655 [inlined]
[10] getindex
@ ./broadcast.jl:610 [inlined]
[11] copy
@ ./broadcast.jl:912 [inlined]
[12] materialize
@ ./broadcast.jl:873 [inlined]
[13] generate_tex_elements(str::LaTeXStrings.LaTeXString, font_family::MathTeXEngine.FontFamily)
@ MathTeXEngine ~/.julia/packages/MathTeXEngine/na9MW/src/engine/layout.jl:301
[14] generate_tex_elements(str::LaTeXStrings.LaTeXString)
@ MathTeXEngine ~/.julia/packages/MathTeXEngine/na9MW/src/engine/layout.jl:295
[15] top-level scope
@ REPL[6]:1
I'm happy to create a PR, but I don't know where to start.
The \boldsymbol
command is not currently supported.
It needs to be added to the parser around here (there is a bit of doc in the parser folder to explain what this does, but essentially it should be the same as for \overline
)
https://github.com/Kolaru/MathTeXEngine.jl/blob/9708b1545645d41dc33355dc19d262d0efd30eab/src/parser/commands_registration.jl#L65
Then, the logic needs to be added to the layout system in the tex_layout
function. Here is the corresponding part for the \overline
command.
https://github.com/Kolaru/MathTeXEngine.jl/blob/9708b1545645d41dc33355dc19d262d0efd30eab/src/engine/layout.jl#L149
For \boldsymbol
, we need to look at the font files to understand where and how to grab the correct bold symbol. If we are lucky it's sufficient to just get the same glyph from the bold font.