-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add align, align*, and equation support
- Loading branch information
1 parent
85f5295
commit b047449
Showing
3 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
open Parser | ||
|
||
let generate_latex_command s l = | ||
let line = "\\"^s in | ||
let args = String.concat "," l in | ||
let line = if args="" then line else Printf.sprintf "%s[%s]" line args in | ||
line;; | ||
|
||
|
||
|
||
let generate_latex l = | ||
let rec unparse acc l = | ||
match l with | ||
| [] -> String.concat " " acc | ||
| Line s::q -> unparse (s::acc) q | ||
| AtomicCmd (s,l)::q -> | ||
let line = generate_latex_command s l in | ||
unparse (line::acc) q | ||
| OneArgCmd (s,l,l2)::q -> | ||
let line = generate_latex_command s l in | ||
let line = Printf.sprintf "%s{%s}" line (unparse [] l2) in | ||
unparse (line::acc) q | ||
| MultipleArgCmd (s,l,l2)::q -> | ||
let line = generate_latex_command s l in | ||
let l = List.map (unparse []) l2 in | ||
let line = Printf.sprintf "%s{%s}" line (String.concat "\n" l) in | ||
unparse (line::acc) q | ||
| _::q -> unparse acc q | ||
in unparse [] l;; | ||
|
||
let env_de_latexer env = | ||
match env with | ||
| e -> e;; | ||
|
||
let re_calculate_env ast = | ||
let rec aux acc ast = | ||
match ast with | ||
| [] -> acc | ||
| Env (s,n)::q when s="align" | ||
-> aux (Math(Printf.sprintf "\\begin{align}%s\\end{align}" (generate_latex n))::acc) q | ||
| Env (s,n)::q when s="align*" | ||
-> aux (Math(Printf.sprintf "\\begin{align*}%s\\end{align*}" (generate_latex n))::acc) q | ||
| Env (s,n)::q when s="equation" | ||
-> aux (Math(Printf.sprintf "\\begin{equation}%s\\end{equation}" (generate_latex n))::acc) q | ||
| Env(s,n)::q | ||
-> let ast = aux [] n in | ||
let ast = List.rev ast | ||
in let env = Env(s,ast) | ||
in aux (env::acc) q | ||
| e::q -> aux (e::acc) q | ||
in List.rev (aux [] ast);; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters