Angus Hollands
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Universal AST in the MyST Document Engine > [!Caution] > This has migrated to the JB team notes: https://hackmd.io/@jupyterbook/SkeK9b9wbg --- > [!Note] TLDR > 1. `xref`s are a core feature of MyST > 2. MyST Sites are the source of truth for resolving `xrefs` > 3. MyST Site build logic does not explicitly design against accidentally breaking PDFs in future. > 4. We should resolve this. At a high-level, this document is effectively proposing that **we formally recognise the status-quo** rather than build out anything new or changing how MyST works. > [!Tip] Goals for Readers > - To clarify unclear wording. > - To annotate the document with questions. ## Context The MyST Document Engine supports a variety of different export formats. These include: - Typst `--typst` - LaTeX `--tex` - Structured Site Data `--site` - Static HTML `--html` In order to target these export types, the MyST Engine builds a project in three phases: 1. General Transforms (referencing, processing, execution, etc.) 2. Target Specialisation (preferred image processing, etc.) 3. Export Rendering (HTML output, LaTeX compilation, etc.) All exports effectively share input from (1), but diverge after (2); the input to each specialisation is identical, but the outputs are different.[^output] The majority of the transforms applied to a MyST Document are build-target agnostic (see (1)) general transforms, such as referencing, and execution processing: ```mermaid graph LR coreA@{ shape: lean-r, label: "Project A" } --> generalA[General Transforms A] --> specialWebA[Specialisation Web A] --> exportWebA[Export Web A]--> webA@{ shape: lean-r, label: "Site A" } generalA --> specialPDFA[Specialisation PDF A] --> exportPDFA[Export PDF A]--> pdfA@{ shape: lean-r, label: "PDF A" } ``` [^output]: Note that we're _not_ talking about _export rendering_ here — this is _before_ the actual LaTeX / Typst rendering and compilation takes place. But, there are some specialisations of the AST tree that need to be performed for export (as in (2)): 1. Preferred image formats (web-friendly formats like `webp` vs static-build formats like `pdf`). 2. Alternative representation of web-only outputs (like widgets), possibly hand-authored. See [the MyST Guide](https://mystmd.org/guide/figures#use-an-image-in-place-of-a-video-for-static-exports) for an example of selecting videos vs PNGs for web vs static export. 3. Content inclusion/exclusion for different audiences, e.g. instructor vs student views. For single-use ASTs (that are build and consumed once), these distinctions are mostly semantic — whether we build and specialise, or do the two in one pass is somewhat irrelevant. However, we must now turn our gaze to another MyST feature: cross-references (xrefs). One of the core features behind the MyST Document Engine is the notion of an xref to facilitate embedding and previewing external content. These are built upon three concepts: 1. The URI for identifying and locating external content e.g. <https://mystmd.org/guide>. 2. The MyST AST Spec that defines a schema for the external content to conform to (`<NAME>.json`), e.g. <https://mystmd.org/guide/frontmatter.json>. 3. A well-defined schema for discovering labeled content (`myst.xref.json`), e.g. <https://mystmd.org/guide/myst.xref.json>. Crucially, the content published to these URIs is a MyST _site_ build. As we've seen above, however, site builds are currently thought of as a specialisation of the MyST AST — they're not formally designed in such a way that it's obvious they are expected to be consumed by other specialisations such as PDF builds. Whilst this is mostly invisible / just works, there are some corner-cases — web-first image formats are chosen, for example.[^mime] Furthermore, in future we might wish to provide author-specialisation of content e.g. `only:typst` that requires pruning by the export engine. If a site build prunes Typst-only content from the AST, it will not be available to Typst builds that consume the content via an xref. Presently, the `raw:typst` directive _does_ persist in site builds, but the reason for this is not explicitly documented. [^mime]: E.g. `.pdf` images are rasterised (lossy) to `.webp`. ## Proposal Given that xrefs are a core feature in the MyST Engine, and their construction atop the site build infrastructure establishes site builds as a source of truth, we have two possible options to improve the uncomfortable/fragile status-quo: 1. Treat xrefs as a site-first feature (such that static builds may have poor behaviour when using xrefs), i.e. the status quo: ```mermaid graph LR coreA@{ shape: lean-r, label: "Project A" } --> generalA[General Transforms A] --> specialWebA[Specialisation Web A] --> exportWebA[Export Web A]--> webA@{ shape: lean-r, label: "Site A" } generalA --> specialPDFA[Specialisation PDF A] --> exportPDFA[Export PDF A]--> pdfA@{ shape: lean-r, label: "PDF A" } coreB@{ shape: lean-r, label: "Project B" } --> generalB[General Transforms B] --> specialWebB[Specialisation Web B] --> exportWebB[Export Web B]--> webB@{ shape: lean-r, label: "Site B" } generalB --> specialPDFB[Specialisation PDF B] --> exportPDFB[Export PDF B]--> pdfB@{ shape: lean-r, label: "PDF B" } webA -.xref.-> generalB; linkStyle 14 stroke:red; ``` 2. Re-think the web specialisation as _generalised_ specialisation, effectively treating site builds as the source of truth: ```mermaid graph LR; coreA@{ shape: lean-r, label: "Project A" } --> generalA[General Transforms A] --> specialWebA[Specialisation Web A] --> exportWebA[Export Web A]--> webA@{ shape: lean-r, label: "Site A" } specialWebA --> specialPDFA[Specialisation PDF A] --> exportPDFA[Export PDF A]--> pdfA@{ shape: lean-r, label: "PDF A" } coreB@{ shape: lean-r, label: "Project B" } --> generalB[General Transforms B] --> specialWebB[Specialisation Web B] --> exportWebB[Export Web B]--> webB@{ shape: lean-r, label: "Site B" } specialWebB --> specialPDFB[Specialisation PDF B] --> exportPDFB[Export PDF B]--> pdfB@{ shape: lean-r, label: "PDF B" } webA -.xref.-> generalB; linkStyle 14 stroke:red; ``` By considering the "Export Web A" step as a transform-free serialisation step, it can be seen that (2) is a linear path, rather than a branching graph. Practically this means that the site export should not drop things that are useful to PDF builds — it should be the _universal_ source of truth. I am introducing the term "Universal AST" to describe this concept that we've been passing around for a while with the MyST Engine. It follows that I suggest we re-frame the site build as a uAST build (whether that means adopting new language or not), that serves as the source of truth for other builds. <!-- ### Example A — Widget Outputs MyST Documents can include rich outputs from kernels. For each output from a cell, the engine encounters a MIME bundle — a collection of rich data associated with well-defined content type keys, e.g. `image/png`. Rendering these MIME bundles into MyST AST is a one-to-many step; for a bundle containing: - `application/vnd.jupyter.widget-view+json` - `image/png` Web exports of MyST can (and prefer to) render `application/vnd.jupyter.widget-view+json` (potentially behind an interaction wrapper), whilst static exports will usually prefer `image/png`. Whilst sometimes we might want the author to control this explicitly — by using something like the `placeholder` system in MyST (or an extension thereof), we should support this out of the box. --> ## Future Work ### Extensibility of Exporters > [!Important] > See https://hackmd.io/h8NTuPFBQImhCKKELOhx2g for a proposal around using the uAST mechanism to generalise and factor-out exporting. ### Specialising Content for Export With a source of truth for all exports that is published to the web, we could add support for author-controlled overrides for markup via e.g. an `only` directive / mechanism: ```markdown :::{only:typst} I LOVE **Typst**. LaTeX _SUCKS_! ::: :::{only:latex} I LOVE **LaTeX**. Typst _SUCKS_! ::: :::{only:html} **EVERYTHING** SUCKS. `XML` WAS A MISSED OPPORTUNITY! ::: ``` ## Related Issues - https://github.com/jupyter-book/mystmd/issues/2615 - https://github.com/jupyter-book/mystmd/issues/1833 - https://github.com/jupyter-book/mystmd/pull/1744 - https://github.com/jupyter-book/mystmd/issues/1759

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully