ymurase
    • 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

      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.
      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
    • Engagement control
    • 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 Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control 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

    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.
    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
    1
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Ottについての知見が集まる魔法のマークダウン とりあえずテンプレート: https://github.com/SoftwareFoundationGroupAtKyotoU/ott-tuto-stlc ## IMPORTANT: ott の推奨オプションについて 1. sysfile は一見便利そうな機能に見えるが、sysfile を使うと何故か lexer の挙動が変わってかなり使いづらくなるので非推奨。 2. -o と -tex_filter を同時に使うと何故か multiple_parses に関するエラーが増える。これも使いづらくなるので非推奨。 以下 [テンプレート](https://github.com/SoftwareFoundationGroupAtKyotoU/ott-tuto-stlc) のMakefileより抜粋 ``` # Tips with ott options: # # 1. We should avoid sysfiles. It is reported that use of sysfiles leads to unexpected lexing issues. # 2. We should avoid use of -o and -tex_filter at the same time. It results in unintended # multiple_parses errors even when any parse results make the same tex output. # %.tex: %.otex $(OTT_PREFIX).ott opam exec -- ott $(OTT_FLAGS) \ -tex_name_prefix $(OTT_PREFIX) \ -i $(OTT_PREFIX).ott \ -tex_filter $< $@ ``` ## 括弧を表示したくはないがOttコード上で結合を明示したい ダミーの括弧(ここでは `?(` と `)?`)を用意する: ``` e {{ tex e }} :: 'expr_' ::= {{ com expressions }} … | ?( e )? :: M :: assoc {{ tex [[e]] }} ``` ## lex の話 * `metavar intvar, n, m ::= {{ lex numeral }}` などとすれば自然数をあらわすメタ変数を定義できる * https://www.cl.cam.ac.uk/~pes20/ott/top2.html#sec40 にある ## ギリシャ文字の話 * `metavar greek, alpha, beta ::= {{ tex \[[greek]] }}` とすれば `$[[alpha]]$` が `$\alpha$` になる * `'a` などで代用可能ではある ## 知見を求む ### 複数行にまたがる式 [求:知見] * 現状、改行やインデントに相当するコンストラクタを定義してやりくりしているがもっと賢いやり方が知りたい(吉岡) * 大変よくわかります(村瀬) ### 変更したら自動でコンパイルしてくれるようにしたい * (村瀬) latexmkとうまく連携してほしい * 一時`omake`(ファイルの自動更新監視機能がある)を使ってました。(五十嵐) * (中村) 正確には Typst というやつで文書を書いてた時の話なのですが、スクリプトを書いてファイルの更新監視をし、コンパイルをぶん回すという力技はやったことがあります。Deno という TypeScript ランタイムを使っていました。応用はできるはずです。 * 参考:https://docs.deno.com/api/deno/~/Deno.watchFs * 同等のことができるコマンドとか、探せばあるかも * ↓実際に使っていたスクリプト(をほんのちょっといじったもの) ```typescript // auto_recompile.ts // 実行:deno --allow-read --allow-run auto_recompile.ts const watcher = Deno.watchFs("./main.typ"); for await (const event of watcher) { if (event.kind === "modify" || event.kind === "create") { await new Deno.Command("typst compile main.typ").spawn().status; // ここで実行するコマンドを omake とかにしたら良さそう } } ``` ### Overleaf との連携 ### [SyncTex](https://github.com/jlaurens/synctex) との連携 - [問題] 各エディターでのPDF viewerからのソースジャンプが機能しない - 以前西田さんが解決策を見つけてくれたが失伝 ### ちょっと dirty hack をやろうとしてハマった話 https://github.com/SoftwareFoundationGroupAtKyotoU/ott-tuto-stlc ここのテンプレートのやつの language.ott に `metavar ident ::= {{ lex alphanum }}` みたいなのを入れると、`grammer G` のところの `empty :: :: empty { tex \epsilon }}` のところのルールなどが `ident` 判定されてちょっと壊れる(それはそうという話かもしれない) `alphanum` でなく `Alphanum` (typo ではない)を使うと、先頭が大文字のものだけを扱うようになるので、`empty` 等は依然使えます。 参考:`lex` の後ろで使えるやつの一覧とか説明とか https://www.cl.cam.ac.uk/~pes20/ott/top2.html#sec40 (村瀬) 自分の経験だとこれは `G` としてのパース結果が優先されるはずなので、壊れるのは何か他の原因がある気がします > `empty :: :: empty { tex \epsilon }}` のところのルールなどが `ident` 判定されてちょっと壊れる この結論についてははやとちりだったかもしれないです。ただ依然ビルドエラーは手元だと再現するのでまた共有しときます。 **環境** ``` $ ott -help Ott version 0.33 distribution of Mon 16 Jan 15:32:01 GMT 2023 (以下略) ``` **やったこと** <details> <summary>加えた変更</summary> ```diff= diff --git a/language.ott b/language.ott index 5d2ce05..8f48548 100644 --- a/language.ott +++ b/language.ott @@ -6,6 +6,7 @@ embed }} metavar x , y ::= {{ com variables }} +metavar ident ::= {{ lex alphanum }} grammar e {{ tex e }} :: 'expr_' ::= {{ com expressions }} ``` </details> <details> <summary> `omake paper` の出力 </summary> ``` *** omake: reading OMakefiles --- Checking for ocamlfind... (found /Users/mityu/.opam/5.2.0/bin/ocamlfind) --- Checking for ocamlc.opt... (found /Users/mityu/.opam/5.2.0/bin/ocamlc.opt) --- Checking for ocamlopt.opt... (found /Users/mityu/.opam/5.2.0/bin/ocamlopt.opt) --- Checking for ocamldep.opt... (found /Users/mityu/.opam/5.2.0/bin/ocamldep.opt) --- Checking for ocamllex.opt... (found /Users/mityu/.opam/5.2.0/bin/ocamllex.opt) --- Checking whether ocamlc understands the "z" warnings... (NO) --- Checking whether ocamlopt can create cmxs plugins... (NO) *** omake: finished reading OMakefiles (0.10 sec) - build . language.tex + ott -writesys language.sys -signal_parse_errors true -tex_show_meta false -tex_wrap false -o languag e.tex language.ott Ott version 0.33 distribution of Mon 16 Jan 15:32:01 GMT 2023 system definition in file: language.sys - build . sections/appendix.tex + ott -readsys language.sys -signal_parse_errors true -tex_filter sections/appendix.otex sections/appe ndix.tex Ott version 0.33 distribution of Mon 16 Jan 15:32:01 GMT 2023 - build . sections/abstract.tex + ott -readsys language.sys -signal_parse_errors true -tex_filter sections/abstract.otex sections/abst ract.tex Ott version 0.33 distribution of Mon 16 Jan 15:32:01 GMT 2023 - build . sections/stlc.tex + ott -readsys language.sys -signal_parse_errors true -tex_filter sections/stlc.otex sections/stlc.tex Ott version 0.33 distribution of Mon 16 Jan 15:32:01 GMT 2023 Fatal error: exception New_term_parser.Reject_parse *** omake: 19/22 targets are up to date *** omake: failed (0.15 sec, 0/0 scans, 4/4 rules, 18/71 digests) *** omake: targets were not rebuilt because of errors: sections/stlc.tex depends on: sections/stlc.otex ``` </details> ## メタレベルの変数 `x` のところにオブジェクトレベルの変数名や具体的定数を書きたい :warning: (追記 by 村瀬) これは sysfile を使った時にだけ発生する lexer の奇妙な挙動に対する hack で、sysfile を使わなければそもそも必要ありません。(参照: 「ott の推奨オプションについて」) 以下のようにかなり厄介なTeX言語ハックをやると,`x` にあたる箇所に `#Vfoo` と書くとオブジェクトレベルの変数名 foo がタイプライタ体で出せるようになり,`#C42` と書くと整数定数 42 が書ける: ``` embed {{ tex-preamble \newcommand\identifier[1]{% \mathit{#1}% } \newcommand\constant[1]{% #1% } \makeatletter \let\local@spaceLetter= \relax \def\local@chop#1#2\local@end{% \ifx\local@spaceLetter#1% local@chop#2\local@end \else \ifx V#1% \identifier{#2}% \else \ifx C#1% \constant{#2}% \else \PrefixOtherThanVOrC \fi \fi \fi } \newcommand\makeIdentOrConst[1]{% \mathtt{\local@chop#1\local@end}% } \makeatother }} metavar uppercased ::= {{ lex Alphanum }} grammar ident {{ tex \cannotUseIdentAsMetavar }} :: 'ident_' ::= {{ com object-level identifiers }} | # uppercased :: :: uppercased {{ tex \makeIdentOrConst{[[uppercased]]} }} x {{ tex x }}, f {{ tex f }} :: 'var_' ::= {{ com variables }} | ident :: :: ident {{ tex [[ident]] }} ```

    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

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    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