-
Notifications
You must be signed in to change notification settings - Fork 20
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
Parse environments #56
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #56 +/- ##
==========================================
- Coverage 75.72% 73.59% -2.14%
==========================================
Files 10 9 -1
Lines 548 568 +20
==========================================
+ Hits 415 418 +3
- Misses 133 150 +17
Continue to review full report at Codecov.
|
Hey @Kolaru, Thank you for the update here! Here is a very quick proof of concept I was exploring to see about parsing out from the parsed text a valid Julia matrix: using MathTeXEngine
expr = texparse(L"""\begin{matrix}1 & ϕ \\3 & 4\end{matrix}""")
rows = []
if expr.args[1].head == :env
env_type = expr.args[1].args[1]
body = expr.args[1].args[2:end]
if env_type == "matrix"
for row in body
cells = []
for cell in row.args
for expression in cell.args
if expression.head == :digit
push!(cells, parse(Int64, expression.args[1]))
else
push!(cells, expression.args[1])
end
end
end
push!(rows, cells)
end
end
end
rows = mapreduce(permutedims, vcat, rows) For this little example, I can recover the original matrix in Julia notation: > 2×2 Matrix{Any}:
1 'ϕ'
3 4 After having explored and experimented with the PR some, here are my thoughts:
Otherwise, AMAZING stuff! |
I have added several changes to take in account your comments.
In example it gives julia> expr = texparse(L"""\begin{matrix}a + \lim_i^j & \alpha \\ u_3 & \sqrt{2}\end{matrix}""")
TeXExpr :expr
└─ TeXExpr :env
├─ "matrix"
└─ Matrix{TeXExpr}
├─ TeXExpr :group
│ ├─ TeXExpr :char
│ │ └─ 'a'
│ ├─ TeXExpr :spaced
│ │ └─ TeXExpr :symbol
│ │ └─ '+'
│ └─ TeXExpr :underover
│ ├─ TeXExpr :function
│ │ └─ "lim"
│ ├─ TeXExpr :char
│ │ └─ 'i'
│ └─ TeXExpr :char
│ └─ 'j'
├─ TeXExpr :decorated
│ ├─ TeXExpr :char
│ │ └─ 'u'
│ ├─ TeXExpr :digit
│ │ └─ '3'
│ └─ nothing
├─ TeXExpr :symbol
│ └─ 'α'
└─ TeXExpr :sqrt
└─ TeXExpr :digit
└─ '2'
# Just grab the matrix of arguments
julia> expr.args[1].args[2]
2×2 Matrix{TeXExpr}:
TeX"a + \lim_i^j" … TeX"α"
TeX"u_3"
TeX"\sqrt{2}" |
I was able to rebase this on the current master with minimal fuss. It looks like it still needs some tests and the layout implementation. |
Superseed #50 (I did not find how I could easily update it directly) and is a first step into implementing #48.
This is still missing tests.
Currently the parsing results in the following:
env
expressions have the name of the environment as first argument and the rows of the env (separated by\\
) as follow up argumentsenv_row
expr, with cells (separated by&
) as argumentsenv_cell
expr can contain arbitrary latex constructs, just like agroup
expr canThe parser performs no check on the name of the environment nor on the structure of the content (e.g. making sure rows have a consistent number of columns). I am not sure whether these checks are better done at parser or layouting level...
@TheCedarPrince I'd love your opinion on that. If the result of the parsing seem reasonnable to you, I will add tests and merge it. Layouting the content of env can be done in a subsequent PR.
Example: