forked from fzimmermann89/texlive.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
205 lines (171 loc) · 5.46 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
<html>
<head>
<style>
h2 {
padding: 0px;
margin: 8px;
}
h3 {
padding: 0px;
margin: 0px;
font-size: 16px;
font-weight: bold;
}
footer {
position: absolute;
bottom: 0;
left: 0;
float: left;
width: 100%;
height: 18em;
}
.left {
float: left;
width: 50%;
}
.right {
float: left;
width: 50%;
}
body {
margin: 0 0 18em;
}
#editor {
position: absolute;
top: 7em;
bottom: 21em;
left: 0;
right: 0;
}
html {
position: relative;
min-height: 100%;
}
</style>
</head>
<body>
<h1>texlive.js - A LaTeX Environment in Javascript</h1>
<a href="https://github.com/fzimmermann89/texlive.js/"><img style="position: absolute; top: 0; right: 0; border: 0;z-index:100" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"></a>
<div id="buttons">
<button id="compile" autofocus>Compile to PDF</button>
<button id="open_pdf_btn" style="display: none">Open PDF</button>
</div>
<div id="editor">
\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}
\end{document}
</div>
<footer>
<div class="both">
<h3>Console Output</h3>
<pre id="output" style="overflow: scroll; font-size:12px; max-height: 7em">Click "Compile to PDF" and watch the console output here.</pre>
<a name="running" id="running" style="display: none">Compiling...<img src="loading.gif" /></a>
</div>
<div class="left">
<h2>Licenses</h2>
<p>GPL/BSD (Ace)/TeXLive's license</p>
</div>
<div class="right">
<h2>Related Projects</h2>
<ul>
<li><a href="https://github.com/manuels/texlive.js">manuels/texlive.js</a>: Pdftex compiled to Javascript</li>
<li><a href="https://github.com/kripken/emscripten">emscripten</a>: An LLVM-to-JavaScript Compiler used to create texlive.js</li>
<li><a href="https://ace.c9.io">Ace Editor</a>: Used for this page</li>
</ul>
</div>
</footer>
</body>
<script src="https://cdn.jsdelivr.net/g/[email protected](min/ace.js+min/ext-language_tools.js+min/mode-latex.js+min/snippets/latex.js)"></script>
<script src="complete/AutoComplete.js"></script>
<script src="promisejs/promise.js"></script>
<script src="pdftex.js"></script>
<script>
var editor = ace.edit("editor");
editor.setOptions({
mode: "ace/mode/latex",
fontSize: 14,
hScrollBarAlwaysVisible: false,
vScrollBarAlwaysVisible: true,
indentedSoftWrap: true,
printMargin: false,
printMarginColumn: false,
tabSize: 4,
useSoftTabs: true,
});
var langTools = ace.require("ace/ext/language_tools")
var AM = ace.require("complete/AutoCompleteManager");
var AutoCompleteManager = new AM.AutoCompleteManager(editor);
AutoCompleteManager.enable();
editor.setOptions({
enableBasicAutocompletion: true,
enableLiveAutocompletion: true,
enableSnippets: true,
});
var visibilityChanger = function(element_id) {
return function(visible) {
document.getElementById(element_id).style.display = visible ? 'inline' : 'none';
}
}
var showLoadingIndicator = visibilityChanger("running")
var showOpenButton = visibilityChanger("open_pdf_btn")
var appendOutput = function(msg) {
var content = document.getElementById("output").textContent;
var output = document.getElementById("output");
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);
var texlive = new TeXLive();
var pdftex = texlive.pdftex;
pdftex.on_stdout = appendOutput;
pdftex.on_stderr = appendOutput;
var start_time = new Date().getTime();
pdftex.compile(source_code).then(function(pdf_dataurl) {
var end_time = new Date().getTime();
console.info("Execution time: " + (end_time - start_time) / 1000 + ' sec');
showLoadingIndicator(false);
if (pdf_dataurl === false)
return;
showOpenButton(true);
document.getElementById("open_pdf_btn").focus();
texlive.terminate();
});
}
document.getElementById("compile").addEventListener("click", function(e) {
var source_code = editor.getValue();
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>
</html>