-
-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvements to the tex rendering pipeline #362
Conversation
nice, sorry I'll be busy until weekend but I'll make sure to review on this then. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left few feedbacks, but in general this is really nice enhancements !
@@ -185,7 +198,7 @@ function format_chunk(chunk::DocChunk, docformat::JMarkdown2tex) | |||
return docformat.keep_unicode ? out : uc2tex(out) | |||
end | |||
|
|||
function format_output(result, docformat::JMarkdown2tex) | |||
function format_output(result, docformat::TexFormat) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will produce "invalid" output texminted
format, right ?
Hightlights.jl will include its own characters around some special characters e.g. _
, so that it will result in weird output for minted output.
How about defining new format_output
for TexMinted
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well spotted. I hadn't figured this out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed it.
However it did make my code have more duplicate lines again.
src/rendering/texformats.jl
Outdated
highlight_str(docformat::TexFormat) = "" | ||
highlight_str(docformat::JMarkdown2tex) = | ||
get_highlight_stylesheet(MIME("text/latex"), docformat.highlight_theme) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe defining render_doc
for JMarkdown2tex
and TexFormat
separately will make more sense ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is probably true. This saved a handful of lines but of course it needs another new functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defined render_doc
separately now
We can update our test when you think this PR is ready. |
A more general thought: Fixing these things I always have to consider what to do with the I propose to remove it from the package. |
yeah, this sounds totally fine. Or we can just make |
This is actually precisely what Weave.jl/src/rendering/texformats.jl Lines 154 to 155 in 5c85315
|
ah, yeah, I just thought about the "dispatch-base" external doc generation, but for now |
Ah, that's probably true. I imagine one could implement a
that dispatches such that first the inner docformat is rendered, and then |
Okay, cool, so do you feel this is ready for review/merge again ? Then I will look into details agains and update tests, etc. |
Renaming This one didn't change too much so I think it is ready for review/merge. |
src/rendering/texformats.jl
Outdated
function uc2tex(::TexFormat, s, escape = false) | ||
for key in keys(latex_symbols) | ||
if escape | ||
s = replace(s, latex_symbols[key] => "|\$\\ensuremath{$(texify(key))}\$|") | ||
else | ||
s = replace(s, latex_symbols[key] => "\\ensuremath{$(texify(key))}") | ||
end | ||
end | ||
return s | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like:
uc2tex(::JMarkdown2tex, s, escape = false) = unicode2tex(s, escape, "*@")
uc2tex(::TexFormat, s, escape = false) = unicode2tex(s, escape, "|\$")
function unicode2tex(s, escape, starter, closer = reverse(starter))
for key in keys(latex_symbols)
body = "\\ensuremath{$(texify(key))}"
target = escape ? string(starter, body, closer) : body
s = replace(s, latex_symbols[key] => body)
end
return s
end
would look more cleaner ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, that's much nicer !
Please put that instead 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or actually I don't think we can just define unicode2tex
and don't use dispatch here; it only adds complexity here imho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, I don't quite get what you are trying to say.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ups, sorry, very bad english, I tied to say:
I think we can just define unicode2tex
and remove uc2tex
. Using dispatches doesn't seem to be necessary here imho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I'm starting to understand.
The dispatch is indeed not necessary, but on the other hand, uc2tex
is currently called 5 times and in one of those cases (
Weave.jl/src/rendering/texformats.jl
Line 179 in b569740
return docformat.keep_unicode ? out : uc2tex(docformat, out) |
you can't hardcode the escape sequence. (Because the calling scope is used for all <:TexFormat
s.
There is however no real need for two names:
unicode2tex(::JMarkdown2tex, s, escape = false) = unicode2tex(s, escape, "*@")
unicode2tex(::TexMinted, s, escape = false) = unicode2tex(s, escape, "|\$"))
function unicode2tex(s, escape, starter, closer = reverse(starter))
for key in keys(latex_symbols)
body = "\\ensuremath{$(texify(key))}"
target = escape ? string(starter, body, closer) : body
s = replace(s, latex_symbols[key] => body)
end
return s
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternatively escape
and the escape sequence starter
and closer
could be made part of the JMarkdown2tex
and TexMinted
struct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds fair, I will like whichever way you would like to choose.
fwiw, merging (or rebasing) master will get rid of legacy test suites and enable much faster gh-action CI. |
oops, I broke the tests again. |
Codecov Report
@@ Coverage Diff @@
## master #362 +/- ##
==========================================
- Coverage 70.89% 69.35% -1.54%
==========================================
Files 23 23
Lines 1254 1263 +9
==========================================
- Hits 889 876 -13
- Misses 365 387 +22
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for your great work, @JonasIsensee !
This small PR relaxes some type restrictions and implements a few small helper functions in the tex rendering pipeline.
There are no changes to
JMarkdown2tex
TexMinted
andTex
now have a template field and by default use the md2pdf.tpl templateThe template was modified to allow for additional
\usepackage{...}
dependencies (defined indocformat.tex_deps
)TexMinted
now produces runnable tex files but becauseHighlights.jl
only works withlstlisting
the standard code highlighting is deactivated.Tex
does not produce a runnable tex file because there is currently no code to define the custom code environments.