-
Notifications
You must be signed in to change notification settings - Fork 16
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
Eqn parser #59
Comments
Related to #57, the equation Michael was presenting can now be constructed using the following C <- latexMatrix(matrix(c(0,1,1,0), nrow=1), matrix = "bmatrix")
B <- latexMatrix('\\beta', ncol = 3, nrow=4, comma=TRUE, prefix.col = 'y_')
B0 <- latexMatrix('\\beta', ncol = 3, nrow=2, comma=TRUE, prefix.col = 'y_') with the presentation construction
can now be presented with the structure first + substitutions printEqn("*H*_0 : **C B** & = %C %B \\\\
& = %B0 = **0**_{(2 `*` 3)}",
list(C=C, B=B, B0=B0), `**`='mathbf', align=TRUE) Or, even more simply if printEqn("*H*_0 : **C B** & = %C %B \\\\
& = %B0 = **0**_{(2 `*` 3)}", align=TRUE) I personally find these much more readable and easier to modify. |
That looks very interesting indeed, but I'll have to study it some more to get a better sense of what can be done with this. |
For future posterity, here's how A <- latexMatrix("a", 2, 2)
B <- latexMatrix("b", 2, 2)
kronecker(A, B) |> Eqn()
# Generate the 'definition' of Kronecker product,
Bmat <- latexMatrix('\\mathbf{B}', ncol=1, nrow=1)
KABmat <- kronecker(A, Bmat)
KAB <- kronecker(A, B)
Eqn("\\mathbf{A} \\otimes \\mathbf{B} = &",
KABmat,
"\\\\[1.5ex]\n= & ",
KAB,
align = TRUE)
source(here::here('dev', 'printEqn.R'))
printEqn("**A** \\otimes **B** = & %KABmat \\\\[1.5ex]
= & %KAB", align=TRUE) |
With the new A <- latexMatrix("a", 2, 2)
B <- latexMatrix("b", 2, 2)
# Generate the 'definition' of Kronecker product,
Bmat <- latexMatrix('\\mathbf{B}', ncol=1, nrow=1)
source(here::here('dev', 'partition.R'))
source(here::here('dev', 'printEqn.R'))
KABmat <- kronecker(A, Bmat) |> partition(rows=1, columns=1)
KAB <- kronecker(A, B) |> partition(rows=2, columns=2)
printEqn("**A** \\otimes **B** = & %KABmat \\\\[1.5ex]
= & %KAB", align=TRUE) The last of which gives EDIT: uploaded wrong jpg. |
In the examples above, we use |
Added. |
Quarto support added for equations by adding |
Great! Hope you don't mind if I tweak the documentation a bit. |
Took some digging, but I finally found a way to make quarto behave well with I'm thinking about using something like |
That looks good. Is it the case that |
Currently, yes, one would need to use I have a working solution to this problem in https://github.com/friendly/matlib/blob/master/dev/Eqn_test_quarto.qmd but it involves a file name constraint in that, for example, |
Is |
The latter; this shouldn't be the user's problem to automate. |
Does it make sense to support |
Yes, I think that's reasonable. It's unfortunate that a side-step is required to deal with MathJax limitations, though having the option to use the more kosher version for PDF outputs is attractive and IMO preferable. |
OK, I'll do that when I have a chance. |
I added support for |
I've placed a barebones parser in
dev/eqn_parser.R
which implements some of the ideas I was thinking w.r.t. reducing the amount of LaTeX code for the novice user, but still allow power users freedom. The idea is to try and reduce equations such asto something analogous to markdown but for LaTeX equations, such as
Of course, the main limitation is that LaTeX has many more environments to choose from, so I've left it possible for users to define what
*
and**
should mean in this context, among others. This parser also allows for macro definitions, where for example'*'
will give\\times
and%n
will give the same string that's currently provided byEqn_newline()
. Other macros starting with%
are easy to add at this point.There are number of other avenues to go, such as detecting Greek letter inputs to, say, replace
beta -> \\beta
to reduce the\\
requirements, but I worry about going too deep here.The text was updated successfully, but these errors were encountered: