Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1ab6334

Browse files
committed
support for MathJax 4.x
1 parentbe0e072 commit1ab6334

File tree

7 files changed

+334
-13
lines changed

7 files changed

+334
-13
lines changed

‎Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ UGLIFYJS = $(realpath ./node_modules/.bin/uglifyjs) \
1212
--beautify\
1313
ascii_only=true,beautify=false
1414

15-
SAMPLES = build/katex-samples.html build/mathjax-v2-samples.html build/mathjax-v3-samples.html
15+
SAMPLES = build/katex-samples.html build/mathjax-v2-samples.html build/mathjax-v3-samples.html build/mathjax-v4-samples.html
1616

1717

1818
default: build

‎docs/index.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,16 @@ <h1>
9696
</p>
9797

9898
<ul>
99+
<li></li>
99100
<li>
100101
<aonclick="load('katex-samples.html')">
101102
<strong>KaTeX</strong> Samples
102103
</a>
103104
</li>
105+
<li></li>
106+
</ul>
107+
108+
<ul>
104109
<li>
105110
<aonclick="load('mathjax-v2-samples.html')">
106111
<strong>MathJax 2</strong> Samples
@@ -111,6 +116,11 @@ <h1>
111116
<strong>MathJax 3</strong> Samples
112117
</a>
113118
</li>
119+
<li>
120+
<aonclick="load('mathjax-v4-samples.html')">
121+
<strong>MathJax 4</strong> Samples
122+
</a>
123+
</li>
114124
</ul>
115125

116126
<ul>
@@ -261,7 +271,7 @@ <h3>Acknowledgement</h3>
261271
</section>
262272

263273
<footer>
264-
<p>This project is maintained by
274+
<p>Project Maintainer:
265275
<ahref="https://github.com/SaswatPadhi">Saswat Padhi</a>
266276
</p>
267277
<p>

‎docs/mathjax-v4-samples.html

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<metacharset="utf-8">
6+
<title>pseudocode.js Samples with MathJax</title>
7+
8+
<!-- Setup MathJax -->
9+
<script>
10+
MathJax={
11+
tex:{
12+
inlineMath:[['$','$'],['\\(','\\)']],
13+
displayMath:[['$$','$$'],['\\[','\\]']],
14+
processEscapes:true,
15+
processEnvironments:true,
16+
}
17+
}
18+
</script>
19+
<scriptsrc="https://cdn.jsdelivr.net/npm/mathjax@4.0.0-beta.3/tex-chtml.js"
20+
integrity="sha256-ljPODBK7Jf/VfUrVqec63xzZbysEmwB9Ab20TWRMQRU="
21+
crossorigin="anonymous">
22+
</script>
23+
24+
<!-- Pseudocode -->
25+
<linkrel="stylesheet"href="pseudocode.css"type="text/css">
26+
<scriptsrc="pseudocode.js"type="text/javascript"></script>
27+
</head>
28+
29+
<body>
30+
<preid="test-basics"data-line-number=true>
31+
\begin{algorithm}
32+
\caption{Test text-style}
33+
\begin{algorithmic}
34+
\REQUIRE some preconditions
35+
\ENSURE some postconditions
36+
\INPUT some inputs
37+
\OUTPUT some outputs
38+
\PROCEDURE{Test-Declarations}{}
39+
\STATE font families: {\sffamily sffamily, \ttfamily ttfamily, \normalfont normalfont, \rmfamily rmfamily.}
40+
\STATE font weights: {normal weight, \bfseries bold, \mdseries
41+
medium, \lfseries lighter. }
42+
\STATE font shapes: {\itshape itshape \scshape Small-Caps \slshape slshape \upshape upshape.}
43+
\STATE font sizes: \tiny tiny \scriptsize scriptsize \footnotesize
44+
footnotesize \small small \normalsize normal \large large \Large Large
45+
\LARGE LARGE \huge huge \Huge Huge \normalsize
46+
\ENDPROCEDURE
47+
\PROCEDURE{Test-Commands}{}
48+
\STATE \textnormal{textnormal,} \textrm{textrm,} \textsf{textsf,} \texttt{texttt.}
49+
\STATE \textbf{textbf,} \textmd{textmd,} \textlf{textlf.}
50+
\STATE \textup{textup,} \textit{textit,} \textsc{textsc,} \textsl{textsl.}
51+
\STATE \uppercase{uppercase,} \lowercase{LOWERCASE.}
52+
\ENDPROCEDURE
53+
\PROCEDURE{Test-Colors}{}
54+
\STATE colors: $\color{red}{red}$, $\color{green}{green}$, $\color{blue}{blue}$
55+
\STATE colors: $\color{yellow}{yellow}$, $\color{cyan}{cyan}$, $\color{magenta}{magenta}$
56+
\ENDPROCEDURE
57+
\end{algorithmic}
58+
\end{algorithm}
59+
60+
\begin{algorithm}
61+
\caption{Test atoms}
62+
\begin{algorithmic}
63+
\STATE \textbf{Specials:} \{ \} \$ \& \# \% \_
64+
\STATE \textbf{Bools:} \AND \OR \NOT \TRUE \FALSE
65+
\STATE \textbf{Carriage return:} first line \\ second line
66+
\STATE \textbf{Text-symbols:} \textbackslash
67+
\STATE \textbf{Quote-symbols:} `single quotes', ``double quotes''
68+
\STATE \textbf{Math:} $(\mathcal{C}_m)$, $i \gets i + 1$, $E=mc^2$, \( x^n + y^n = z^n \), $\$$, \(\$\)
69+
\END{ALGORITHMIC}
70+
\END{ALGORITHM}
71+
</pre>
72+
<preid="test-codes">
73+
\begin{algorithm}
74+
\caption{Test control blocks}
75+
\begin{algorithmic}
76+
\PROCEDURE{Test-If}{}
77+
\IF{&lt;cond&gt;}
78+
\STATE &lt;block&gt;
79+
\ELIF{&lt;cond&gt;}
80+
\STATE &lt;block&gt;
81+
\ELSE
82+
\STATE &lt;block&gt;
83+
\ENDIF
84+
\ENDPROCEDURE
85+
\PROCEDURE{Test-For}{$n$}
86+
\STATE $i \gets 0$
87+
\FOR{$i<n$}
88+
\PRINT$i$
89+
\STATE$i\getsi+1$
90+
\ENDFOR
91+
\ENDPROCEDURE
92+
\PROCEDURE{Test-For-To}{$n$}
93+
\STATE$i\gets0$
94+
\FOR{$i$\TO$n$}
95+
\PRINT$i$
96+
\ENDFOR
97+
\ENDPROCEDURE
98+
\PROCEDURE{Test-For-DownTo}{$n$}
99+
\FOR{$i\getsn$\DOWNTO$0$}
100+
\PRINT$i$
101+
\ENDFOR
102+
\ENDPROCEDURE
103+
\PROCEDURE{Test-For-All}{$n$}
104+
\FORALL{$i\in\{0,1,\cdots,n\}$}
105+
\PRINT$i$
106+
\ENDFOR
107+
\ENDPROCEDURE
108+
\PROCEDURE{Test-While}{$n$}
109+
\STATE$i\gets0$
110+
\WHILE{$i<n$}
111+
\PRINT$i$
112+
\STATE$i\getsi+1$
113+
\ENDWHILE
114+
\ENDPROCEDURE
115+
\PROCEDURE{Test-Repeat}{$n$}
116+
\STATE$i\gets0$
117+
\REPEAT
118+
\PRINT$i$
119+
\STATE$i\getsi+1$
120+
\UNTIL{$i>n$}
121+
\ENDPROCEDURE
122+
\PROCEDURE{Test-Break-Continue}{$n$}
123+
\FOR{$i = 0$ \TO $2n$}
124+
\IF{$i<n/2$}
125+
\CONTINUE
126+
\ELIF{$i> n$}
127+
\BREAK
128+
\ENDIF
129+
\PRINT $i$
130+
\ENDFOR
131+
\ENDPROCEDURE
132+
\end{algorithmic}
133+
\end{algorithm}
134+
\begin{algorithm}
135+
\caption{Test statements and comments}
136+
\begin{algorithmic}
137+
\PROCEDURE{Test-Statements}{}
138+
\STATE This line is a normal statement
139+
\PRINT \texttt{`this is print statement'}
140+
\RETURN $retval$
141+
\ENDPROCEDURE
142+
143+
\PROCEDURE{Test-Comments}{} \COMMENT{comment for procedure}
144+
\STATE a statement \COMMENT{inline comment}
145+
\STATE \COMMENT{line comment}
146+
\IF{some condition}\COMMENT{comment for if}
147+
\RETURN \TRUE \COMMENT{another inline comment}
148+
\ELSE \COMMENT{comment for else}
149+
\RETURN \FALSE \COMMENT{yet another inline comment}
150+
\ENDIF
151+
\ENDPROCEDURE
152+
\end{algorithmic}
153+
\end{algorithm}
154+
</pre>
155+
<preid="test-examples"data-title-prefix="Procedure">
156+
% This quicksort algorithm is extracted from Chapter 7, Introduction
157+
% to Algorithms (3rd edition)
158+
\begin{algorithm}
159+
\caption{Quicksort}
160+
\begin{algorithmic}
161+
\PROCEDURE{Quicksort}{$A, p, r$}
162+
\IF{$p<r$}
163+
\STATE$q =$\CALL{Partition}{$A,p,r$}
164+
\STATE\CALL{Quicksort}{$A,p,q-1$}
165+
\STATE\CALL{Quicksort}{$A,q+1,r$}
166+
\ENDIF
167+
\ENDPROCEDURE
168+
\PROCEDURE{Partition}{$A,p,r$}
169+
\STATE$x =A[r]$
170+
\STATE$i =p-1$
171+
\FOR{$j =p$\TO$r-1$}
172+
\IF{$A[j]<x$}
173+
\STATE$i =i+1$
174+
\STATEexchange
175+
$A[i]$with$A[j]$
176+
\ENDIF
177+
\STATEexchange$A[i]$with$A[r]$
178+
\ENDFOR
179+
\ENDPROCEDURE
180+
\end{algorithmic}
181+
\end{algorithm}
182+
</pre>
183+
<preid="test-examples-custom-title">
184+
% This quicksort algorithm is extracted from Chapter 7, Introduction
185+
% to Algorithms (3rd edition)
186+
\begin{algorithm}
187+
\caption{Quicksort}
188+
\begin{algorithmic}
189+
\PROCEDURE{Quicksort}{$A, p, r$}
190+
\IF{$p<r$}
191+
\STATE$q =$\CALL{Partition}{$A,p,r$}
192+
\STATE\CALL{Quicksort}{$A,p,q-1$}
193+
\STATE\CALL{Quicksort}{$A,q+1,r$}
194+
\ENDIF
195+
\ENDPROCEDURE
196+
\PROCEDURE{Partition}{$A,p,r$}
197+
\STATE$x =A[r]$
198+
\STATE$i =p-1$
199+
\FOR{$j =p$\TO$r-1$}
200+
\IF{$A[j]<x$}
201+
\STATE$i =i+1$
202+
\STATEexchange
203+
$A[i]$with$A[j]$
204+
\ENDIF
205+
\STATEexchange$A[i]$with$A[r]$
206+
\ENDFOR
207+
\ENDPROCEDURE
208+
\end{algorithmic}
209+
\end{algorithm}
210+
</pre>
211+
<preclass="scopeline-pseudocode"data-line-number=true>
212+
\begin{algorithm}
213+
\caption{Classical Euclidean Algorithm}
214+
\begin{algorithmic}
215+
\PROCEDURE{Euclid}{$a,b$}
216+
\WHILE{$a \neq b$}
217+
\IF{$a> b$}
218+
\STATE $a \gets a - b$
219+
\ELSE
220+
\STATE $b \gets b - a$
221+
\ENDIF
222+
\ENDWHILE
223+
\RETURN $a$
224+
\ENDPROCEDURE
225+
\end{algorithmic}
226+
\end{algorithm}
227+
</pre>
228+
<preclass="scopeline-pseudocode"data-no-end=true>
229+
\begin{algorithm}
230+
\caption{DBSCAN}
231+
\begin{algorithmic}
232+
\INPUT A dataset $D$, the $\varepsilon$ distance threshold, and the minimum number of points $minPts$
233+
\OUTPUT A set of clusters $K$
234+
\PROCEDURE{DBSCAN}{$D, \varepsilon, minPts$}
235+
\STATE $K \gets \emptyset$
236+
\FORALL{$p \in D$}
237+
\IF{$p$ has not been visited}
238+
\STATE mark $p$ as visited
239+
\STATE $N_{\varepsilon}(p) \gets $ \textsc{RangeQuery}$(p, \varepsilon, D)$
240+
\IF{$N_{\varepsilon}(p)<minPts$}
241+
\STATEmark$p$asnoise
242+
\ELSE
243+
\COMMENT{pisacoreobject}
244+
\STATE$C\gets$\textsc{ExpandCluster}$(p,N_{\varepsilon}(p))$
245+
\STATE$K\getsK\cup\{C\}$
246+
\ENDIF
247+
\ENDIF
248+
\ENDFOR
249+
\RETURN$K$
250+
\ENDPROCEDURE
251+
\end{algorithmic}
252+
\end{algorithm}
253+
</pre>
254+
<script>
255+
pseudocode.renderElement(document.getElementById("test-basics"),
256+
{
257+
lineNumber:false,
258+
noEnd:true
259+
});
260+
pseudocode.renderElement(document.getElementById("test-codes"));
261+
pseudocode.renderElement(document.getElementById("test-examples"),
262+
{
263+
lineNumber:true,
264+
noEnd:false
265+
});
266+
pseudocode.renderElement(document.getElementById("test-examples-custom-title"),
267+
{
268+
lineNumber:true,
269+
noEnd:false,
270+
titlePrefix:"My pretty Algorithm"
271+
});
272+
pseudocode.renderClass("scopeline-pseudocode",{scopeLines:true});
273+
</script>
274+
</body>
275+
</html>

‎docs/pseudocode.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎pseudocode.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ module.exports = {
2525
if(baseDomEle)
2626
baseDomEle.appendChild(elem);
2727

28-
if(R.backend&&R.backend.name==='mathjax'&&R.backend.version<3)
29-
MathJax.Hub.Queue(["Typeset",MathJax.Hub,elem]);
28+
if(R.backend&&R.backend.name==='mathjax'){
29+
if(MathJax.version<3)
30+
MathJax.Hub.Queue(["Typeset",MathJax.Hub,elem]);
31+
elseif(MathJax.version>3)
32+
MathJax.typeset();
33+
// We use synchronous conversion in MathJax 3.x
34+
}
3035

3136
returnelem;
3237
},
@@ -37,7 +42,7 @@ module.exports = {
3742

3843
varR=makeRenderer(input,options);
3944
if(R.backend&&R.backend.name==='mathjax'&&R.backend.version<3){
40-
console.warn('`renderToString` isnotfully supported on MathJax backendbelow 3.0.\n'+
45+
console.warn('`renderToString` is fully supportedonlyon MathJax backend3.x.\n'+
4146
'Math ($...$) will not be rendered to HTML and will be left as is.');
4247
}
4348

@@ -58,8 +63,13 @@ module.exports = {
5863
varnewElem=R.toDOM();
5964
elem.replaceWith(newElem);
6065

61-
if(R.backend&&R.backend.name==='mathjax'&&R.backend.version<3)
62-
MathJax.Hub.Queue(["Typeset",MathJax.Hub,elem]);
66+
if(R.backend&&R.backend.name==='mathjax'){
67+
if(MathJax.version<3)
68+
MathJax.Hub.Queue(["Typeset",MathJax.Hub,elem]);
69+
elseif(MathJax.version>3)
70+
MathJax.typeset();
71+
// We use synchronous conversion in MathJax 3.x
72+
}
6373
},
6474

6575
renderClass:function(className,options){

‎src/Renderer.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,14 @@ TextEnvironment.prototype.renderToHTML = function (backend) {
167167
this._html.putHTML(backend.driver.renderToString(text));
168168
}
169169
elseif(backend.name==='mathjax'){
170-
if(backend.version<3){
171-
// keep math text, typeset later
172-
this._html.putText(`$${text}$`);
173-
}
174-
else{
170+
if(backend.version===3){
175171
// use synchronous conversion available in 3.x
176172
this._html.putHTML(backend.driver.tex2chtml(text,{display:false}).outerHTML);
177173
}
174+
else{
175+
// keep math text, typeset later
176+
this._html.putText(`$${text}$`);
177+
}
178178
}
179179
else{
180180
thrownewEvalError(`Unknown math backend${backend}`);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp