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

[Tutorials] Fixes for LaTeX and cell source #3401

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

CristianLara
Copy link
Contributor

This is a duplicate of the same code change in botorch: pytorch/botorch#2752

LaTeX in Tutorials

Docusaurus 3 requires math to be wrapped in $ delimiters. We were trying to be backwards compatible with our existing tutorials by wrapping math blocks in $ delimiters while converting to MDX but properly handling every type of math block (which this was failing to do) is beyond the scope of this script.

Since these tutorials are intended to be consumed by Docusaurus lets just enforce the $ delimiters when writing tutorials.

Tutorial cell source

I was noticing that sometimes (depending on a variety of factors like the editor used to modify the tutorial, whether they had been executed) the conversion script would fail because the cell source would be stored as a list of strings instead of a multi-line string.

From the official nbformat documentation:

Some fields, such as code input and text output, are characteristically multi-line strings. When these fields are written to disk, they may be written as a list of strings, which should be joined with '' when reading back into memory. In programmatic APIs for working with notebooks (Python, Javascript), these are always re-joined into the original multi-line string. If you intend to work with notebook files directly, you must allow multi-line string fields to be either a string or list of strings.

https://ipython.readthedocs.io/en/3.x/notebook/nbformat.html

This is a duplicate of the same code change in botorch: pytorch/botorch#2752

Docusaurus 3 requires math to be wrapped in $ delimiters. We were trying to be backwards compatible with our existing tutorials by wrapping math blocks in $ delimiters while converting to MDX but properly handling every type of math block (which this was failing to do) is beyond the scope of this script.

Since  these tutorials are intended to be consumed by Docusaurus lets just enforce the $ delimiters when writing tutorials.
This is a duplicate of the same code change in botorch: pytorch/botorch#2752

I was noticing that sometimes (depending on a variety of factors like the editor used to modify the tutorial, whether they had been executed) the conversion script would fail because the cell source would be stored as a list of strings instead of a multi-line string.

From the official nbformat documentation:

> Some fields, such as code input and text output, are characteristically multi-line strings. When these fields are written to disk, they may be written as a list of strings, which should be joined with '' when reading back into memory. In programmatic APIs for working with notebooks (Python, Javascript), these are always re-joined into the original multi-line string. If you intend to work with notebook files directly, you must allow multi-line string fields to be either a string or list of strings.

https://ipython.readthedocs.io/en/3.x/notebook/nbformat.html
@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Feb 21, 2025
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.99%. Comparing base (63a1eaf) to head (a4d9028).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3401   +/-   ##
=======================================
  Coverage   95.99%   95.99%           
=======================================
  Files         539      539           
  Lines       52794    52794           
=======================================
  Hits        50677    50677           
  Misses       2117     2117           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants