-
Notifications
You must be signed in to change notification settings - Fork 156
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
Various improvements in the rendering of math and references. rST ZIPs now support $...$ for inline math. #953
Open
daira
wants to merge
9
commits into
zcash:main
Choose a base branch
from
daira:easier-math-in-rst
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,656
−2,365
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cd3f23e
CSS: Make the style of reference links and references (almost) consis…
daira d5d9643
ZIP 225: use math in some tables.
daira 70ed5c5
ZIPs 231, 234, 235: Minor formatting and reference fixes.
daira 49f2555
Support `$...$` for inline math in reStructuredText.
daira ba09951
Use `$...$` for inline math in existing reStructuredText ZIPs.
daira 936223b
Switch from MathJax to KaTeX. fixes #432
daira e1ddb75
Various formatting tweaks.
daira 673cbc7
Rewrite the rendering in a more functional style.
daira 96dafb2
Re-render.
daira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
*.save | ||
*.save.* | ||
*~ | ||
*.html.temp | ||
|
||
.Makefile.uptodate | ||
.zipfilelist.* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
if ! ( ( [ "x$1" = "x--rst" ] || [ "x$1" = "x--pandoc" ] || [ "x$1" = "x--mmd" ] ) && [ $# -eq 3 ] ); then | ||
cat - <<EndOfUsage | ||
Usage: render.sh --rst|--pandoc|--mmd <inputfile> <htmlfile> <title> | ||
--rst render reStructuredText using rst2html5 | ||
--pandoc render Markdown using pandoc | ||
--mmd render Markdown using multimarkdown | ||
EndOfUsage | ||
exit | ||
fi | ||
|
||
inputfile="$2" | ||
outputfile="$3" | ||
|
||
if ! [ -f "${inputfile}" ]; then | ||
echo "File not found: ${inputfile}" | ||
exit | ||
fi | ||
|
||
if [ "x$1" = "x--rst" ]; then | ||
filetype='.rst' | ||
else | ||
filetype='.md' | ||
fi | ||
title="$(basename -s ${filetype} ${inputfile} | sed -E 's|zip-0{0,3}|ZIP |; s|draft-|Draft |')$(grep -E '^(\.\.)?\s*Title: ' ${inputfile} |sed -E 's|.*Title||')" | ||
echo " ${title}" | ||
|
||
Math1='<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-nB0miv6/jRmo5UMMR1wu3Gz6NLsoTkbqJghGIsx//Rlm+ZU03BU6SQNC66uf4l5+" crossorigin="anonymous">' | ||
Math2='<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-7zkQWkzuo3B5mTepMUcHkMB5jZaolc2xDwL6VFqjFALcbeS9Ggm/Yr2r3Dy4lfFg" crossorigin="anonymous"></script>' | ||
Math3='<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-43gviWU0YVjaDtb/GhzOouOXtZMP/7XUzwPTstBeZFe/+rCMvRwr4yROQP43s0Xk" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script>' | ||
ViewAndStyle='<meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="css/style.css">' | ||
|
||
cat <( | ||
if [ "x$1" = "x--rst" ]; then | ||
# These are basic regexps so \+ is needed, not +. | ||
# We use the Unicode 💲 character to move an escaped $ out of the way, | ||
# which is much easier than trying to handle escapes within a capture. | ||
cat "${inputfile}" \ | ||
| sed 's|[\][$]|💲|g; | ||
s|[$]\([^$]\+\)[$]\([.,:;!?)-]\)|:math:`\1\\!`\2|g; | ||
s|[$]\([^$]\+\)[$]|:math:`\1`|g; | ||
s|💲|$|g' \ | ||
| rst2html5 -v --title="${title}" - \ | ||
| sed "s|<script src=\"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\"></script>|${Math1}\n ${Math2}\n ${Math3}|; | ||
s|</head>|${ViewAndStyle}</head>|" | ||
else | ||
if [ "x$1" = "x--pandoc" ]; then | ||
# Not actually MathJax. KaTeX is compatible if we use the right headers. | ||
pandoc --mathjax --from=markdown --to=html "${inputfile}" --output="${outputfile}.temp" | ||
else | ||
multimarkdown ${inputfile} -o "${outputfile}.temp" | ||
fi | ||
# Both pandoc and multimarkdown just output the HTML body. | ||
echo "<!DOCTYPE html>" | ||
echo "<html>" | ||
echo "<head>" | ||
echo " <title>${title}</title>" | ||
echo " <meta charset=\"utf-8\" />" | ||
if grep -q -E 'class="math( inline)?"' "${outputfile}.temp"; then | ||
echo " ${Math1}" | ||
echo " ${Math2}" | ||
echo " ${Math3}" | ||
fi | ||
echo " ${ViewAndStyle}" | ||
echo "</head>" | ||
echo "<body>" | ||
cat "${outputfile}.temp" | ||
rm -f "${outputfile}.temp" | ||
echo "</body>" | ||
echo "</html>" | ||
fi | ||
) \ | ||
| sed \ | ||
's|<a href="[^":]*">Protocol Specification</a>|<span class="lightmode"><a href="https://zips.z.cash/protocol/protocol.pdf">Protocol Specification</a></span>|g; | ||
s|\s*<a href="[^":]*">(dark mode version)</a>|<span class="darkmode" style="display: none;"><a href="https://zips.z.cash/protocol/protocol-dark.pdf">Protocol Specification</a></span>|g; | ||
s|<a \(class=[^ ]* \)*href="\([^":]*\)\.rst\(\#[^"]*\)*">|<a \1href="\2\3">|g; | ||
s|<a \(class=[^ ]* \)*href="\([^":]*\)\.md\(\#[^"]*\)*">|<a \1href="\2\3">|g; | ||
s|<\(https:[^&]*\)>|\<<a href="\1">\1</a>\>|g; | ||
s|src="../rendered/|src="|g; | ||
s|<a href="rendered/|<a href="|g; | ||
s|<a \(class=[^ ]* \)*href="zips/|<a \1href="|g' \ | ||
| perl -p0e \ | ||
's|<section id="([^"]*)">\s*.?\s*<h([1-9])>([^<]*(?:<code>[^<]*</code>[^<]*)?)</h([1-9])>|<section id="\1"><h\2><span class="section-heading">\3</span><span class="section-anchor"> <a rel="bookmark" href="#\1"><img width="24" height="24" class="section-anchor" src="assets/images/section-anchor.png" alt=""></a></span></h\4>|g' \ | ||
> "${outputfile}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Yes I had to add
--mathjax
(relative to thepandoc
command that was previously in theMakefile
) as part of switching from MathJax to KaTeX. That's because KaTeX is compatible with MathJax's representation of math spans as:(
class="math inline"
also works.) Previously the\(
\)
delimiters were not being added bypandoc
; that's what the--mathjax
option does.multimarkdown
adds them without an explicit option.