mitex-rs / mitex Goto Github PK
View Code? Open in Web Editor NEWLaTeX support for Typst, powered by Rust and WASM. https://mitex-rs.github.io/mitex/
Home Page: https://mitex-rs.github.io/mitex/tools/underleaf.html
License: Apache License 2.0
LaTeX support for Typst, powered by Rust and WASM. https://mitex-rs.github.io/mitex/
Home Page: https://mitex-rs.github.io/mitex/tools/underleaf.html
License: Apache License 2.0
When curly group is used as an argument, a trailing space is read after the argument.
Lines 552 to 556 in c53aaa3
mitex/crates/mitex-parser/tests/ast/arg_match.rs
Lines 4 to 18 in c53aaa3
#import "@preview/mitex:0.2.1": *
#set math.equation(numbering: "(1)", supplement: [#text(blue)[*Eq.*]])
#mitext(`
\begin{align}
\text{Stokes formula for Manifold $\mathcal M$}\quad \int_{\mathcal M}\mathrm{d}\omega&=\int_{\partial\mathcal M}\omega
\end{align}
`)
Resulting
where the nested math \mathcal M$
is not correctly rendered.
While
#import "@preview/mitex:0.2.1": *
#set math.equation(numbering: "(1)", supplement: [#text(blue)[*Eq.*]])
#mitext(`
\begin{align}
\text{Stokes formula for Manifold}~$\mathcal M$\quad \int_{\mathcal M}\mathrm{d}\omega&=\int_{\partial\mathcal M}\omega
\end{align}
`)
is OK
In latex, something like $$\boxed{\frac12}$$
gives the below.
When just using typst's box, $#box($1/2$, stroke: 0.5pt)$
gives the below.
Ideally, the output would like this #box($1/2$, stroke: 0.5pt, inset: 6pt)
.
It seems that 6pt's of inset is enough to avoid clipping into contents: #box([abcd $1/2$ $1/2/2/2/2/2/2/2/2/2/2/2/(2/2)$], stroke: 0.5pt, inset: 6pt)
.
Does it make sense to change how \boxed
is converted into typst to match the latex output, or is there a good workaround?
My thoughts for a workaround was to use an iftypst
block to replace \boxed
with my own call to #box
, but I think that would then require another conversion inside of the #box
argument from latex to typst.
It would be useful if the CLI had a watch command to automatically update the .typ file when the .tex file changes.
flalign
can not be parsed correctly.
Currently, Lexer treats a single dollar sign and multiple dollar signs as the same token, so we can't distinguish between an inline equation and a block equation.
mitex/crates/mitex-lexer/src/lib.rs
Lines 433 to 434 in 41a666c
If I get it correctly, for the time being, mitex only works as a WASM module and thus only works on the typst web app, but not for the CLI.
It would be better to provide a CLI program that runs like:
mitex -i foo.tex -o foo.typ
Then we can deal with the typst source with typst-cli.
Another benefit of this is that we can easily build a testset with a bunch of TeX sources, which will largely assure the quality and stability of mitex.
It says: xarrow: input symbol must be of type symbol
, Example:
\xarrowright{z}
It appears that theres extra spaces in the definitions for lceil
and rceil
. I'm not sure why they're there, and there may be a good reason for it. However, it causes the results in underleaf as shown in the images below (having a space after the first $
seems to make equations centered).
mitex/packages/mitex/specs/latex/standard.typ
Lines 105 to 107 in ead7177
In overleaf, there is no middle alignment, and the results show up inline.
mitex's design of spliting spec and parser/lexer is very clever and impressive. It however make it harder for people to understand what's happening. It would be better we can have a doc explaining what will happen when you type #mi(
...)
related: #46 (comment) #147
Scanned by script
\notag
\brack
\triangle
\impliedby
\LaTeX
\space
\lnot
\mathop
\vert
\middle
\lvert
\rvert
\lVert
\Bbb
\implies
\boxed
\checkmark
\substack
\dotsb
\dbinom
\*
\wedge
\subsetneqq
\emptyset
\pod
\lor
\cr
\tag
\varphi*
\brace
\begin{alignedat}
Right now the reference is not parsed in mitext
. But I think it can be easily supported by breaking the macro by the parser if \cite
is encountered.
For example, if I have a bib file containing one item called anderson1972more
,
#import "@preview/mitex:0.2.1": *
#mitext(`This is reference test \cite{anderson1972more}. This is the text after.`)
I would expect it to be parsed into
#import "@preview/mitex:0.2.1": *
#mitext(`This is reference test `) @anderson1972 #mitext('. This is the text after.`)
where we can simply take advantage of the standard support of bib-file citation.
Nowadays typst already support #footnote
macro, but #mixtext
still cannot parse \footnote{...}
yet.
I wonder if it can be easily supported by splitting #mitext
with the parser if \footnote
is encountered, like following:
#import "@preview/mitex:0.2.1": *
#mitext(`
Now because only non-trivial braiding\footnote{Otherwise the relabeling among these overlapping pairs takes no effects.} processes are considered...
`)
be parsed by
#import "@preview/mitex:0.2.1": *
#mitext(`
Now because only non-trivial braiding`)#footnote[Otherwise the relabeling among these overlapping pairs takes no effects.]#mitext(` processes are considered...
`)
I copied the example from the README and pasted it to the web app. The code, which is below.
#import "@preview/mitex:0.1.0": *
#assert.eq(mitex-convert("\alpha x"), "alpha x ")
Write inline equations like #mi("x") or #mi[y].
Also block equations (this case is from #text(blue.lighten(20%), link("https://katex.org/")[katex.org])):
#mitex(`
\newcommand{\f}[2]{#1f(#2)}
\f\relax{x} = \int_{-\infty}^\infty
\f\hat\xi\,e^{2 \pi i \xi x}
\,d\xi
`)
After trying to compile it I got "Plugin errored with error: error unknown command \f". Am I doing something wrong or is the library in the preview repository doesn't support the feature yet?
Is it possible to load an image in a iftypst
block?
I've been able to use typst.ts
with mapShadow
in the browser to render images. However, when I try to put this image in a iftypst
block, I get a "failed to load file (access denied)", trace: [Call(Some("mimath"))], hints: ["cannot read file outside of project root"
error.
It seems to me that the web demo is able to import both a bibliography and another template file. However, I cannot figure out where inpackages/mitex-web/src
this virtual file system is handled. It appears that there is a VFS for the sidebar directory view, but I cannot tell how this integrates with mitex
. Is there some documentation on this?
For example,
#import "@preview/mitex:0.2.1": *
#mitext(`
The torus geometry paratermized with fluxes $phi_1,phi_2$ can be described with the struct:
```julia
struct Torus_Sample
L1::Float64
ฯ::ComplexF64
Ns::Int64
mag_trans_units::Vector{ComplexF64}
phase_twists_over_2ฯ::Vector{Float64} # fluxes (ฯ1,ฯ2)
end
```
where we introduce the *minimal* quantized intervals of the sample along two oblique directions $(\delta L_1,\delta L_2)=(\frac{L_1}{N_s},\frac{L_1\tau}{N_s})$, such that each thin rectangular is pierced with just *one* quantum flux
\begin{equation*}
\delta L_1\times L_2 = 2\pi\ell^2,\quad \delta L_2\times L_1 = 2\pi\ell^2.
\end{equation*}
`)
does not render at all.
I encounter this problem because I am transferring my academical notes from markdown (very long and hundreds of huge equations, so rendering slow in markdown) to typst (which is really fast).
Maybe #raw()
macro support can be added for pair of `...` and ```...```, which is not the keyword in latex so should work out without any ambiguities.
Mitex cli should be able to support ctan, as most latex documents use a lot of packages. The initial possible implementation could include just outputting packages.typ
file alongside the converted user file.
I am genuinely impressed with potential of this project and excited about the possibilities it offers. However, I've encountered a bit of a roadblock. As a new user, I'm unsure about the installation process, as the current README file doesn't include an installation section. This has made it challenging for me to get started with the project.
Could you please consider adding an installation guide to the README?
\%
is converted into percent
, but this is correct only if in the equation environment.
Though I prefer to writing documents in pure typst, I need to write several LaTeX documents for formal publications. Typst has delightful future but we have to admit that it cannot be used for writing that documents at least in next few months.
Now, I still want to fully make use of typst, So I want to have a MiTeX which converts at least main body part of TeX code to typst code for me. So that I can preview a LaTeX document locally without help of TeXLive or TeXStudio. I also want to have capability to embed typst content, e.g. cetz pictures into the document, so that I don't have to use tikz.
In conclusion, I feel it useful for partially supporting to convert entire TeX document into typst. With that you can:
Convert entire document into typst sounds crazy, but we still have a chance. We can support them with some limitation, since we are converting a user document.
Idea follows.
\input{chapterN}
with help of mitex(read('chapterN.tex'))
.\iftypst
, so that I can make hacks in my TeX document.
\iftypst
expands only if the document is compiled by typst.\newcommand
.
Not quite hard, no much efforts, but looks perfect for typst users writing TeX documents!
Postscript here. I don't mention more complex things, such as tables, since I plan to do some hacks on them. Personally, I may read and process data by typst scripting, then I either
typst query
, and use TeX's tables showing data processed by typst.No plan, but some direction:
Initial Idea is following.
#locate(loc => layout(size => {
// converted code here
}))
Example 1 (paragraph):
\everypar{\setbox\parbox=
\vbox\bgroup\everypar{}%
\def\par{\endgraf\HandleLines
\egroup\box\parbox}}
\def\HandleLines{ ... \lastbox ... }
Example 2 (box):
\newbox\linebox \newbox\snapbox
\def\eatlines{
\setbox\linebox\lastbox % check the last line
\ifvoid\linebox
\else % if it's not empty
\unskip\unpenalty % take whatever is
{\eatlines} % above it;
% collapse the line
\setbox\snapbox\hbox{\unhcopy\linebox}
% depending on the difference
\ifdim\wd\snapbox<.98\wd\linebox
\box\snapbox % take the one or the other,
\else \box\linebox \fi
\fi}
Hi, I found that that both \mathbf .
and \mathbf{...}
cannot be correctly rendered in desired form as in LaTeX (bold AND regular). For example,
#import "@preview/mitex:0.2.2": *
#mitext(`Reciprocal vector is $\mathbf G$ or $\mathbf{G}$`)
NOTE:
\bm
(as well as\boldsymbol
(please also add support for this command)) behaves different from\mathbf
!
And here is one more tricky thing:
See https://tex.stackexchange.com/questions/294561/using-textbf-vs-mathbf-in-math-mode. Precisely, \mathbf{...}
and \textbf{...}
are different in LaTeX, in that \mathbf{...}
will remove ALL blank spaces within its arguments. So probably a more correct rendering is to parse, for example, for the LaTeX code:
$\sum_{i\in\mathcal I}\mathbf{Op With Space}=\text{blablabla}$
as the Typst code:
$ sum_(i in cal(I))bold(#"Op With Spaces".replace(" ", ""))="blablabla" $
I think this clearly demonstrate how to fix the \mathbf
rendering problem : )
Thanks for your help!
\left\lbrack\lbrack x\rbrack\right\rbrack
becomes
lr(bracket.lbracket.l x bracket.r bracket.r)
Note the consecutive bracket.l, this triggers compile error.
related: OI-wiki/OI-wiki#5475
Previous issue: #35
mitex is well tested by fixtures extracted from oiwiki, which always use mimath (math mode), while you are using mitext (text mode), which is not well tested.
Considering that, the introduction in README.md are misleading, since it wrongly tells mitex in text mode is also well tested. The introduction was correct as I wrote it when we only implemented math mode. However, once after introducing text mode, there should be quite misleading.
document
, figure
, algorithm
and description
.
algorithm
and tikz
, we should parse them correctly and put warning boxes in place.\displaystyle\operatorname{tr}A=\sum\limits_{i}(A)_{ii}
Some useful list of such commands https://github.com/OrangeX4/mitex/blob/main/crates/mitex-lexer/src/macro_engine.rs#L7-L77
\AA
\Box
\C
\L
\LARGE
\N
\O
\P
\Q
\R
\S
\Vert
\Z
\ae
\aleph
\amalg
\arctg
\arraystretch
\arrowvert
\asymp
\atop
\atopwithdelims
\bbox
\begin
\bra
\buildrel
\cdotp
\ch
\check
\circeq
\cline
\colon
\cth
\dag
\ddag
\def
\diamondsuit
\em
\emph
\end
\eqslantgtr
\eqslantless
\expandafter
\fbox
\flat
\hbox
\hfil
\hfill
\hline
\hskip
\i
\idotsint
\includegraphics
\itshape
\j
\kern
\ket
\l
\left
\lgroup
\llap
\lower
\lq
\mathnormal
\mathstrut
\mbox
\mit
\mkern
\mskip
\multicolumn
\natural
\nonumber
\o
\oslash
\overwithdelims
\preceq
\r
\raise
\raisebox
\ref
\relax
\rgroup
\right
\rlap
\root
\rule
\sc
\setlength
\sharp
\shortparallel
\skew
\sl
\smallint
\smash
\smile
\ss
\strut
\succeq
\surd
\textcircled
\textup
\tg
\th
\u
\vcenter
\verb
\vline
\widehat
\widetilde
\wp
Compilation failed when mitex imported using latest typst version 0.11.0
The minimal example for align environment is:
#import "@preview/mitex:0.2.1": *
#set math.equation(numbering: "(1)", supplement: [#text(blue)[*Eq.*]])
#mitext(`
This is \emph{math} \textbf{equation} test for \eqref{eq:1}.
\begin{align}
\text{Stokes formula}\quad \int_{\mathcal M}\mathrm{d}\omega&=\int_{\partial\mathcal M}\omega\nonumber\\
\textbf{Jacobi-}$\vartheta$ \textbf{Function}\quad f(z)&=e^{ik\cdot z}\prod_{\nu=1}^{N_s}\vartheta\left(2\pi\frac{z-z_\nu}{L_1}\middle|\tau\right).\label{eq:1}
\end{align}
`)
Here the label is NOT correctly placed at the end of the second line, even if I use the command \nonumber
for the first line.
Hi, after several days trial of mitex, I found several annoying inconsistencies, even for standard math notation:
[
and parenthesis (
to represent the close and open set. But when I try to convert my notes including something like $[0,1,\cdots, N_s)$ blablabla
, I got serious parse error (collapse to one line)It seems because the parser found some unclosed/unpaired bracket. If so, that is really stupid to me (we should be free to use any symbol in math mode).
$|\boldsymbol k\rangle$
is wrongly parsed by mitex: I got extra spaces between k and the vertical line. But if I try to make it converting from $\ket{\boldsymbol k}$
by explicitly telling mitex what the composite symbol is (here is the ket state), then the conversion is OK.In latex at least
$|\boldsymbol k\rangle$
and$\ket{\boldsymbol k}$
looks the same, without knowing the meaning for the composite symbol|...\rangle
, and there are indeed some situation when$\bra{...}$
or$\ket{...}$
or$\braket{...}$
cannot handle, that is why most people still control the size of vertical line|
and the size of angle bracket\langle
and\rangle
by hand.
_x
is converted as _(x)
, should possible generate a expression for attaching to empty content zws_(x)
Example:
#import "@preview/mitex:0.2.0": *
#mitex(`\textcolor{orange}{test}`)
caused this problem:
Unknown variable: tex
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.