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

Allow the use of custom operator/function name #1

Open
Azercoco opened this issue Jul 25, 2024 · 5 comments
Open

Allow the use of custom operator/function name #1

Azercoco opened this issue Jul 25, 2024 · 5 comments

Comments

@Azercoco
Copy link

I would like to convert a mathematical expression with sech inside. sech is actually a typst function but not a LaTeX one, so in the LaTeX code, I need to add \DeclareMathOperator{\sech}{sech}.

It would be nice if this was taken into account by the convertor. Right now, I need to do additionnal pre and post processing to achieve the correct conversion.

@qwinsi
Copy link
Owner

qwinsi commented Jul 25, 2024

OK. I will try to make this work

@Azercoco
Copy link
Author

After looking into KaTex documentation, the correct way to make it work is to use \newcommand{\sech}{\operatorname{sech}}. This yields the translation into typst to 'op("sech")', while it should only be 'sech'.

From my template, I know at least the following operator are default in typst but not in LateX :

  • sech
  • csch
  • sgn

Ideally, we should compare https://katex.org/docs/supported#math-operators and the Typst predefined operators :

https://typst.app/docs/reference/math/op/.

@Azercoco
Copy link
Author

Azercoco commented Jul 25, 2024

I did a review and the supported ones in typst but not in KaTeX are :

  • dim
  • id
  • im
  • mod
  • Pr
  • sech
  • csch

Actually sgn, and csch are supported by neither.

So I would suggest :

  • For the previoulsy mentionned operators, convert LaTeX \operatorname{sech} to just typst sech for eg.
  • Otherwise, for clarity, instead of converting every LaTeX \operatorname{opr} to op("opr"), create typst preprocessor : #let opr = $op("opr") and then use it as a preamble for the typst code.
  • Maybe also automatically convert the \DeclareMathOperator{...} from ansmath to \newcommand{...}{\operatorname{...}}

EDIT, I miss it but actually csch is defined in Typst.

@qwinsi
Copy link
Owner

qwinsi commented Jul 25, 2024

Well, I will try to improve it as the following:

  • Allow to turn the converter to "non-strict" mode. In such mode, any unrecognized LaTeX command (e.g. \myopr) will be translated to just myopr.
    And the Web App will show additional text area to remind the user to add #let myopr = $op("myopr"); before the Typst math block.
  • For operators already supported by Typst (e.g. sech), convert LaTeX \operatorname{sech} to just typst sech instead of op("sech")

@qwinsi
Copy link
Owner

qwinsi commented Jul 26, 2024

The improvement described above has been applied. Check it in the Web App.
Ideally, there should be some front-end UI interface to customize the options. I don't have much front-end development skills, so the front-end interface is in the plan but won't be done within recent days.

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

No branches or pull requests

2 participants