korsbo / Latexify.jl

Convert julia objects to LaTeX equations, arrays or other environments.
MIT License
562 stars 59 forks source link

Allow recipes to set previous operation #292

Closed gustaphe closed 3 months ago

gustaphe commented 4 months ago

Previously, recipes had no way of affecting the previous operation. With this (somewhat ugly) change, a type that fundamentally represents for instance a multiplication or sum can tell latexify, so that things like parentheses work out right.

Part of fixing #280

TODO

codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 77.81%. Comparing base (6af2a54) to head (1577e93). Report is 2 commits behind head on master.

:exclamation: Current head 1577e93 differs from pull request most recent head ce2cc6e

Please upload reports for the commit ce2cc6e to get more accurate results.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #292 +/- ## ========================================== - Coverage 81.78% 77.81% -3.97% ========================================== Files 21 21 Lines 818 834 +16 ========================================== - Hits 669 649 -20 - Misses 149 185 +36 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

gustaphe commented 4 months ago

Without this,

julia> struct SimpleLength
x
end

julia> @latexrecipe function f(x::SimpleLength)
return Expr(:latexifymerge, x.x, "\\;\\mathrm{m}")
end

julia> @latexify $(SimpleLength(3))^2
3\;\mathrm{m}^2

With this

julia> @latexrecipe function f(x::SimpleLength)
operation := :*
return Expr(:latexifymerge, x.x, "\\;\\mathrm{m}")
end

julia> @latexify $(SimpleLength(3))^2
\left( 3\;\mathrm{m} \right)^{2}