Skip to content

Commit 85f5295

Browse files
author
Charlotte Thomas
committed
add very WIP math gestion (of $ $) with codecogs API
1 parent cf7f10f commit 85f5295

File tree

5 files changed

+43
-11
lines changed

5 files changed

+43
-11
lines changed

lib/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
(library
44
(name htmlfromtexbooks)
5-
(libraries str netstring))
5+
(libraries str))

lib/htmlgen.ml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ open Parser
22
open Glossary
33
open Utils
44

5-
let url_encoded_str s = Netencoding.Url.encode s;;
5+
let url_encoded_str s = s;;
66

77
let print_table_of_content ast min_chap =
88
let count = [|1;1;1;1|] in
@@ -58,9 +58,9 @@ let print_table_of_content ast min_chap =
5858
| _::q -> aux acc q
5959
in (aux "" ast);;
6060

61-
let parse_to_html ?(min_chap=1) ast=
61+
let parse_to_html ?(min_chap=1) write_before ast=
6262
let count = [|1;1;1;1|] in
63-
let rec aux ?(write=false) acc ast =
63+
let rec aux ?(write=write_before) acc ast =
6464
match ast with
6565
| [] -> acc
6666
| Nul::q -> aux acc q
@@ -209,9 +209,10 @@ let prepare_body name str toc =
209209
doc;;
210210

211211

212-
let print_file_in_html ?(min_chap=1) file outname =
212+
let print_file_in_html ?(min_chap=1) ?(write_before=false) file outname =
213213
let a = pre_parse_file file in
214-
let html = parse_to_html ~min_chap:min_chap a in
214+
let html = parse_to_html ~min_chap:min_chap write_before a in
215215
let toc = print_table_of_content a min_chap in
216-
prepare_body (Hashtbl.find preamble "title") html toc
216+
let name = try Hashtbl.find preamble "title" with _ -> "Generic" in
217+
prepare_body name html toc
217218
|> write_to_file outname;;

lib/parser.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ let rec parse_string str =
9494
let rec parse current_acc acc lst =
9595
match lst with
9696
| [] -> append_line current_acc acc
97-
| t::q when t='$' -> let a,q2 = parse_math q in parse "" (a::acc) q2
97+
| t::q when t='$' -> let a,q2 = parse_math q in parse "" (a::(append_line current_acc acc)) q2
9898
| t::q when t='\\' ->
9999
let cmd,l = parse_command q in
100100
parse "" (Cmd(cmd)::(append_line current_acc acc)) l

test.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<title>Generic</title>
2+
<body>
3+
<style>
4+
.center {
5+
margin:auto;
6+
text-align:center;
7+
}
8+
</style><div class="center">
9+
<h1>Generic</h1>
10+
<h2>Table of Content</h2>
11+
<ul>
12+
13+
</ul>
14+
</div>
15+
tralalala
16+
</p>
17+
18+
<p>
19+
20+
This is an integral
21+
<img src="https://latex.codecogs.com/svg.image?x"/>
22+
<div style="margin: auto; text-align: center;">
23+
au center
24+
25+
</div>
26+
<i><b>!!!
27+
</b></i>selsle
28+
29+
30+
31+
</body>

test.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
\documentclass{article}
2-
\newcommand{\sep}{\begin{center}
3-
\boldmath $\ast$~$\ast$~$\ast$
4-
\end{center}}
52
\usepackage{babel}
63
Hello
74
\begin{document}
85
tralalala
6+
\bigskip
7+
This is an integral
8+
$\int^a_b f(x) \mathrm{d}x$
99
\begin{center}
1010
au center
1111
\end{center}

0 commit comments

Comments
 (0)