forked from manuels/texlive.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
220 lines (176 loc) · 6.95 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<!doctype html>
<html>
<head>
<style>
html {
font-family: Arial;
}
textarea {
font-family: monospace;
width: 100%;
}
code {
background: #eee;
}
code .string {
color: rgb(102, 153, 0);
}
code .keyword {
color: rgb(0, 119, 170);
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
/* <![CDATA[ */
// flattr button
(function() {
var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];
s.type = 'text/javascript';
s.async = true;
s.src = 'http://api.flattr.com/js/0.6/load.js?mode=auto';
t.parentNode.insertBefore(s, t);
})();
/* ]]> */</script>
</head>
<body>
<script src="promisejs/promise.js"></script>
<script src="pdftex.js"></script>
<h1>texlive.js – A LaTeX Compiler for Javascript</h1>
<a href="https://github.com/manuels/texlive.js/"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"></a>
<h2>
Usage
</h2>
<code style="width: 55em; margin: 0 auto; padding: 1em; display: block">
<span class="keyword">var</span> pdftex = <span class="keyword">new</span> PDFTeX();<br />
<span class="keyword">var</span> latex_code = <span class="string">""</span> + <br />
<span class="string"> "\\documentclass{article}"</span> + <br />
<span class="string"> "\\begin{document}"</span> + <br />
<span class="string"> "\\LaTeX is great!"</span> + <br />
<span class="string"> "$E = mc^2$"</span> + <br />
<span class="string"> "\\end{document}"</span>;
<br /><br />
pdftex.compile(latex_code)<br />
.then(<span class="keyword">function</span>(pdf) {
window.open(pdf)
});
</code>
<div id="tabs">
<div class="tab" id="tab_input">
<h2>
Demo
</h2>
<h3>
LaTeX Input
</h3>
<button id="compile" autofocus>Compile this LaTeX code to a PDF</button>
<a class="FlattrButton" style="display:none;" rev="flattr;button:compact;" href="http://github.com/manuels/texlive.js"></a>
<button onclick="TogetherJS(this); return false;">Start Collaboration Mode</button>
<textarea rows="30" id="input">
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{graphicx}
\title{\TeX live.js}
\author{Created by Manuel Sch\"olling}
\date{\today}
\begin{document}
\maketitle
\TeX{}live.js is a compiler for the \TeX{}
typesetting program created using Mozilla's Emscripten
Compiler. It offers programmable desktop
publishing features and extensive facilities for
automating most aspects of typesetting and desktop
publishing, including numbering and cross-referencing,
tables and figures, page layout, bibliographies, and
much more. It supports \LaTeX{} which was originally written
in 1984 by Leslie Lamport and has become the dominant method for
using \TeX;
% This is a comment, not shown in final output.
% The following shows typesetting power of LaTeX:
\begin{align}
E_0 &= mc^2 \\
E &= \frac{mc^2}{\sqrt{1-\frac{v^2}{c^2}}}
\end{align}
\TeX{}live.js even supports images! This photo was taken by Laura Poitras/Praxis Films
\includegraphics[height=5cm, keepaspectratio]{snowden}
\end{document}
</textarea>
</div>
<div class="tab" id="tab_output">
<h3>Console Output</h3>
<pre id="output" style="overflow: scroll; max-height: 300px">
Click "Compile this LaTeX code to PDF" at the top of this page and watch the console output here.
</pre>
<a name="running" id="running" style="display: none">
Compiling…
<img src="loading.gif" />
</a>
</div>
<div class="tab" id="tab_open_pdf" style="display: none">
<h3>View your PDF</h3>
<button id="open_pdf_btn">Open your PDF</button>
<p>
Your LaTeX code is now compiled to a PDF document. The document is converted to a <a href="https://developer.mozilla.org/en-US/docs/data_URIs">data URI</a> that makes it possible to interpret the format correctly.
</p>
<a name="open_pdf"></a>
</div>
</div>
<h2>License</h2>
<p>GNU/GPL</p>
<h2>More Information</h2>
<p>Checkout the <a href="https://github.com/manuels/texlive.js/wiki">wiki page</a></p>
<h2>Related Projects</h2>
<ul>
<li><a href="https://github.com/mozilla/pdf.js">pdf.js</a>: a PDF reader in Javascript by Mozilla</li>
<li><a href="https://github.com/kripken/emscripten">emscripten</a>: An LLVM-to-JavaScript Compiler used to create texlive.js</li>
</ul>
<script>
var visibilityChanger = function(element_id) {
return function(visible) {
document.getElementById(element_id).style.display = visible ? 'block' : 'none';
}
}
var showLoadingIndicator = visibilityChanger("running")
var showOpenButton = visibilityChanger("tab_open_pdf")
var appendOutput = function(msg) {
var output = document.getElementById("output");
var content = output.textContent;
output.textContent = content + "\r\n" + msg;
output.scrollTop = 999999;
console.log(msg);
}
var pdf_dataurl = undefined;
var compile = function(source_code) {
document.getElementById("output").textContent = "";
showLoadingIndicator(true);
window.location.href = "#running";
var pdftex = new PDFTeX();
pdftex.set_TOTAL_MEMORY(80*1024*1024).then(function() {
pdftex.FS_createLazyFile('/', 'snowden.jpg', 'snowden.jpg', true, true);
pdftex.on_stdout = appendOutput;
pdftex.on_stderr = appendOutput;
console.time("Execution time");
pdftex.compile(source_code).then(function(pdf_dataurl) {
console.timeEnd("Execution time");
showLoadingIndicator(false);
if (pdf_dataurl === false)
return;
showOpenButton(true);
window.location.href = "#open_pdf";
document.getElementById("open_pdf_btn").focus();
});
});
}
document.getElementById("compile").addEventListener("click", function(e) {
var source_code = document.getElementById("input").value;
compile(source_code);
});
document.getElementById("open_pdf_btn").addEventListener("click", function(e) {
window.open(pdf_dataurl);
e.preventDefault();
});
var pdftex_preload = new PDFTeX("pdftex-worker.js");
pdftex_preload = undefined;
</script>
<script src="https://togetherjs.com/togetherjs-min.js"></script>
</body>
</html>