Skip to content
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
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

daira
Copy link
Collaborator

@daira daira commented Nov 8, 2024

  • Make the style of reference links and references (almost) consistent between Markdown and reStructuredText.

  • The $...$ syntax can now be —and is— used in rST, except in tables and headings. fixes Make $...$ work in reStructuredText ZIPs #952

    The reason why $...$ doesn't work in general for tables and headings is that replacing it with :math:`...` throws off the column-sensitive markup. Things like that are why column-sensitive markup is a bad idea.

  • In most cases when using $...$ followed by a punctuation mark, there is no need to manually correct spacing (in either rST or Markdown). The render.sh script does it automatically if required. This does not apply to :math:`...`.

  • Math is rendered using KaTeX instead of MathJax. fixes Switch from MathJax to KaTeX for ZIP rendering #432, fixes The size of rendered math in ZIPs is inconsistent between reloads #375

  • The rendering of math from Markdown is greatly improved. Previously it could only handle simple expressions that could be rendered at low quality as text; now it supports everything that KaTeX supports, and the quality of rendering is consistent (if not quite up to pdflatex standards).

  • This PR is also preparation for switching to MultiMarkdown. MultiMarkdown fixes the duplicate reference bug (References are duplicated in the rendering of Markdown ZIPs #893) and also has some nice features like colspan in tables (use $n$ | characters on the right-hand-side of a table entry to make it span $n$ columns).

@daira
Copy link
Collaborator Author

daira commented Nov 8, 2024

This should be merged after #951 [edit: which is now merged].

@daira daira marked this pull request as draft November 8, 2024 14:32
@daira daira marked this pull request as ready for review November 8, 2024 20:12
@daira daira requested a review from str4d November 8, 2024 20:15
@daira daira requested a review from nuttycom November 8, 2024 23:10
@daira
Copy link
Collaborator Author

daira commented Nov 8, 2024

When reviewing this, please also check how reference links and the References section look after the CSS changes. That might vary between browsers; I only tested desktop Firefox (115.1.0esr) and Chromium (124.0.6367.118) on Debian. It's difficult to test mobile without having GitHub Pages rendering of PRs.

@daira daira changed the title Easier math in reStructuredText Easier math in reStructuredText; make references consistent between Markdown and rST Nov 9, 2024
@daira daira changed the title Easier math in reStructuredText; make references consistent between Markdown and rST Make references consistent between Markdown and rST, and allow $...$ for inline math in rST Nov 9, 2024
@daira daira added S-scratching-an-itch Status: Something we haven't planned for a sprint but are doing anyway ZIP rendering labels Nov 9, 2024
@daira daira changed the title Make references consistent between Markdown and rST, and allow $...$ for inline math in rST Various improvements in the rendering of math and references. rSt now supports $...$ for inline math. Nov 9, 2024
@daira daira force-pushed the easier-math-in-rst branch 2 times, most recently from f472b90 to a9fc3ae Compare November 9, 2024 22:36
@daira daira force-pushed the easier-math-in-rst branch 3 times, most recently from 7e35f12 to 7c2bd6c Compare November 10, 2024 04:56
@daira daira changed the title Various improvements in the rendering of math and references. rSt now supports $...$ for inline math. Various improvements in the rendering of math and references. rST ZIPs now support $...$ for inline math. Nov 10, 2024
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"
Copy link
Collaborator Author

@daira daira Nov 10, 2024

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 the pandoc command that was previously in the Makefile) as part of switching from MathJax to KaTeX. That's because KaTeX is compatible with MathJax's representation of math spans as:

<span class="math">\(latex code\)</span>

(class="math inline" also works.) Previously the \( \) delimiters were not being added by pandoc; that's what the --mathjax option does. multimarkdown adds them without an explicit option.

@daira
Copy link
Collaborator Author

daira commented Nov 10, 2024

The reason why I didn't just immediately switch to MultiMarkdown in this PR, is that it is not packaged for Linux distributions. It has to be built from source (requiring CMake, for the current version). The build is pretty straightforward though, so I'll switch the default once I've added it to the docker image and added some documentation.

…tent

between Markdown and reStructuredText.

(This also anticipates a possible switch from Pandoc to Multimarkdown;
the changes are designed to work with both.)

Signed-off-by: Daira-Emma Hopwood <[email protected]>
Signed-off-by: Daira-Emma Hopwood <[email protected]>
(zip-guide *incorrectly* said that we were already using KaTeX. This has
been wrong since zcash#645.)

Signed-off-by: Daira-Emma Hopwood <[email protected]>
Signed-off-by: Daira-Emma Hopwood <[email protected]>
This supports MultiMarkdown as well as Pandoc, using
`make MARKDOWN_OPTION=--mmd`

Signed-off-by: Daira-Emma Hopwood <[email protected]>
Signed-off-by: Daira-Emma Hopwood <[email protected]>
Copy link
Contributor

@nuttycom nuttycom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK with minor questions

preprocessrst.sh Outdated
# which is much easier than trying to handle escapes within a capture;
# I don't even know if the latter is possible.

sed 's|[\][$]|💲|g' "$1" | sed 's|[$]\([^$]\+\)[$]|:math:`\1`|g' | sed 's|💲|$|g'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever approach!

Comment on lines 34 to 39
If the expiry is at block height $N\!$, then the transaction must be included in block
$N$ or earlier. Block $N+1$ will be too late, and the transaction will be
removed from the mempool.

The new consensus rule will enforce that the transaction will not be considered valid if
included in block of height greater than $N$, and blocks that include expired
included in block of height greater than $N\!$, and blocks that include expired
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the additions of \! here? Elsewhere in this commit I've seen a bunch of removals, and I'm not sure what the change means.

@@ -145,15 +145,15 @@ Transaction Format
|``1`` |``flagsOrchard`` |``byte`` |An 8-bit value representing a set of flags. Ordered from LSB to MSB: |
| | | | * ``enableSpendsOrchard`` |
| | | | * ``enableOutputsOrchard`` |
| | | | * The remaining bits are set to ``0``. |
| | | | * The remaining bits are set to :math:`0\!`. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these still using :math: instead of $...$?

+-----------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------+
|``8`` |``valueBalanceOrchard`` |``int64`` |The net value of Orchard spends minus outputs. |
+-----------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------+
|``32`` |``anchorOrchard`` |``byte[32]`` |A root of the Orchard note commitment tree at some block |
| | | |height in the past. |
+-----------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------+
|``varies`` |``sizeProofsOrchard`` |``compactSize`` |Length in bytes of ``proofsOrchard``. Value is |
| | | |:math:`2720 + 2272 \cdot \mathtt{nActionsOrchard}`. |
| | | |:math:`2720 + 2272 \cdot \mathtt{nActionsOrchard}\!`. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question.

From the Asset Digest, we derive a specific Asset Base within each shielded protocol using the applicable hash-to-curve algorithm. This Asset Base is included in shielded notes.

Let

- $\mathsf{asset\_desc}$ be the asset description, which includes any information pertaining to the issuance, and is a byte sequence of up to 512 bytes which SHOULD be a well-formed UTF-8 code unit sequence according to Unicode 15.0.0 or later.
- $\mathsf{ik}$ be the issuance validating key of the issuer, a public key used to verify the signature on the issuance transaction's SIGHASH.

Define $\mathsf{AssetDigest_{AssetId}} := \textsf{BLAKE2b-512}(\texttt{"ZSA-Asset-Digest"},\; \mathsf{EncodeAssetId}(\mathsf{AssetId}))\!$,
Define $\mathsf{AssetDigest_{AssetId}} := \textsf{BLAKE2b-512}(\texttt{ZSA-Asset-Digest},\; \mathsf{EncodeAssetId}(\mathsf{AssetId}))$,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unicode quotes like this are a little annoying; unless you have the correct editor they're a challenge to work with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-scratching-an-itch Status: Something we haven't planned for a sprint but are doing anyway ZIP rendering
Projects
None yet
2 participants