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

Add render hook for 'chem' code blocks #1286

Merged
merged 1 commit into from
Dec 5, 2022
Merged

Conversation

deining
Copy link
Collaborator

@deining deining commented Oct 17, 2022

With PR #987 merged, math code blocks can now be used to display mathematical formulae, Based on this work, this PR adds the feature to use chem code blocks to display chemical formulae. With this PR merged, you can now write something like:

```chem
\ce{SO4^2- + Ba^2+ -> BaSO4 v}
```

Please note that this PR relies on render hook templates, a feature that is available as of hugo 0.93. For users with older hugo versions., the old, now deprecated way of coding a formulae on its own line is still available.

Furthermore, this PR brings in some additions that streamline and ease the use of formulae for technical writers:

  • When `math' or 'chem' blocks are used on a page, the required scripts are now loaded automatically. There is no need to enable KaTeX and/or ´mhchem´ in the site configuration any more (only when using hugo 0.93 or newer).

  • Up to now, KaTeX and/or mhchem scripts were enabled in the sitewide config file. Once enabled, scripts were loaded for all pages, even it there were no formulae present on the page. With this PR in place, activation of scripts is now possible on a per page basis, too, simply by adding attributes in the page front matter:

+++
math = true
chem = true
+++

Also, the documentation page in the user guide was adapted in order to reflect the changes introduced with this PR.

@deining deining requested a review from LisaFC October 17, 2022 09:36
@deining deining force-pushed the chem-render-hook branch 5 times, most recently from 45247dd to bd2c927 Compare October 23, 2022 19:20
@deining deining force-pushed the chem-render-hook branch 4 times, most recently from 39339ab to 13bda31 Compare October 29, 2022 05:24
@geriom
Copy link
Collaborator

geriom commented Dec 1, 2022

This is so cool!

The changes to mermaid diagrams introduced conflicts here. @deining can you take a look and fix the merge conflicts?

Sorry for taking so long to review this.

@deining
Copy link
Collaborator Author

deining commented Dec 1, 2022

@deining can you take a look and fix the merge conflicts?

Done.

Auto activation of `math' and 'chem' blocks
Add ability to enable KateX and/or mhchem for individual pages only
Upgrade to KaTeX 0.16.3
Copy link
Collaborator

@geriom geriom left a comment

Choose a reason for hiding this comment

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

Thank you!

@geriom geriom merged commit 2c11f53 into google:main Dec 5, 2022
@deining deining deleted the chem-render-hook branch December 5, 2022 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants