Skip to content

Commit 3eaceea

Browse files
committed
Minor changes & clarifications in README
1 parent 574122d commit 3eaceea

File tree

8 files changed

+97
-100
lines changed

8 files changed

+97
-100
lines changed
File renamed without changes.

Makefile

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
.PHONY: default setup lint build release clean
1+
.PHONY: build clean docs default lint release setup
22

33
VERSION=2.0
44

55
# Building tools
66
BROWSERIFY = $(realpath ./node_modules/.bin/browserify)
7+
CLEANCSS = $(realpath ./node_modules/.bin/cleancss)
8+
ESLINT = $(realpath ./node_modules/.bin/eslint)
79
WATCHIFY = $(realpath ./node_modules/.bin/watchify)
810
UGLIFYJS = $(realpath ./node_modules/.bin/uglifyjs) \
911
--mangle \
1012
--beautify \
1113
ascii_only=true,beautify=false
12-
CLEANCSS = $(realpath ./node_modules/.bin/cleancss)
13-
ESLINT = $(realpath ./node_modules/.bin/eslint)
1414

1515
SAMPLES = build/katex-samples.html build/mathjax-v2-samples.html build/mathjax-v3-samples.html
1616

17+
1718
default: build
1819

1920

@@ -28,6 +29,12 @@ static/katex/:
2829
@echo "> Katex downloaded"
2930

3031

32+
33+
watch-js: pseudocode.js $(wildcard src/*.js)
34+
$(WATCHIFY) $< --standalone pseudocode -o build/pseudocode.js
35+
36+
37+
3138
build: build/pseudocode.js build/pseudocode.css $(SAMPLES)
3239
@echo "> Building succeeded"
3340

@@ -38,17 +45,14 @@ build/pseudocode.js: pseudocode.js $(wildcard src/*.js)
3845
lint: pseudocode.js $(wildcard src/*.js)
3946
$(ESLINT) $^
4047

41-
# Watch the changes to js source code and update the target js code
42-
watch-js: pseudocode.js $(wildcard src/*.js)
43-
$(WATCHIFY) $< --standalone pseudocode -o build/pseudocode.js
44-
4548
build/pseudocode.css: static/pseudocode.css
4649
cp static/pseudocode.css build/pseudocode.css
4750

4851
build/%-samples.html: static/%-samples.html.template
4952
cp $< $@
5053

5154

55+
5256
release: build build/pseudocode-js.tar.gz build/pseudocode-js.zip
5357
@echo "> Release package generated"
5458

@@ -70,5 +74,13 @@ build/pseudocode.min.css: build/pseudocode.css
7074
$(CLEANCSS) -o $@ $<
7175

7276

77+
78+
docs: build/pseudocode.min.js build/pseudocode.min.css $(SAMPLES)
79+
cp build/pseudocode.min.css docs/pseudocode.css
80+
cp build/pseudocode.min.js docs/pseudocode.js
81+
cp $(SAMPLES) docs/
82+
83+
84+
7385
clean:
74-
@rm -rf build/*
86+
@rm -rf build/*

README.md

Lines changed: 49 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
1-
# Pseudocode.js - Beautiful pseudocode for the Web
1+
# pseudocode.js - Beautiful pseudocode for the Web
22

3-
Pseudocode.js is a JavaScript library that typesets pseudocode beautifully to
3+
<img align="right" width="42%" src="docs/screenshot.png">
4+
5+
**pseudocode.js** is a JavaScript library that typesets pseudocode beautifully to
46
HTML.
57

6-
* **Intuitive grammar**: Pseudocode.js takes a LaTeX-style input that supports
8+
* _Intuitive grammar:_ Pseudocode.js takes a LaTeX-style input that supports
79
the algorithmic constructs from LaTeX's algorithm packages. With or without
810
LaTeX experience, a user should find the grammar fairly intuitive.
9-
* **Print quality:** The HTML output produced by pseudocode.js is (almost)
11+
* _Print quality:_ The HTML output produced by pseudocode.js is (almost)
1012
identical with the pretty algorithms printed on publications that are
1113
typeset by LaTeX.
12-
* **Math formula support:** Inserting math formulas in pseudocode.js is as easy
14+
* _Math formula support:_ Inserting math formulas in pseudocode.js is as easy
1315
as LaTeX. Just enclose math expression in `$...$` or `\(...\)`.
1416

1517
It supports all modern browsers, including Chrome, Safari, Firefox, Edge, and
1618
IE 9 - IE 11.
1719

20+
1821
## Demo
1922
Visit the [project website](https://saswatpadhi.github.io/pseudocode.js) for demo.
2023

24+
2125
## Usage
2226

2327
### Quick Start
2428

25-
Pseudocode.js can render math formulas using either
29+
pseudocode.js can render math formulas using either
2630
[KaTeX](https://github.com/Khan/KaTeX), or [MathJax](https://www.mathjax.org/).
2731

2832
#### Step 1A &middot; For KaTeX users
2933
Include the following in the `<head>` of your page:
3034

3135
```html
32-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.css"
33-
integrity="sha256-V8SV2MO1FUb63Bwht5Wx9x6PVHNa02gv8BgH/uH3ung=" crossorigin="anonymous" />
3436
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.js"
3537
integrity="sha256-F/Xda58SPdcUCr+xhSGz9MA2zQBPb0ASEYKohl8UCHc=" crossorigin="anonymous">
3638
</script>
@@ -83,68 +85,51 @@ Then include the following in the `<head>` of your page:
8385
<script src="//path/to/pseudocode/pseudocode.min.js"></script>
8486
```
8587

86-
8788
#### Step 3 &middot; Write your pseudocode inside a `<pre>`
8889
We assume the pseudocode to be rendered is in a `<pre>` DOM element.
8990
Here is an example that illustrates a quicksort algorithm:
9091

9192
```tex
92-
% This quicksort algorithm is extracted from Chapter 7, Introduction to Algorithms (3rd edition)
93-
\begin{algorithm}
94-
\caption{Quicksort}
95-
\begin{algorithmic}
96-
\PROCEDURE{Quicksort}{$A, p, r$}
97-
\IF{$p < r$}
98-
\STATE $q = $ \CALL{Partition}{$A, p, r$}
99-
\STATE \CALL{Quicksort}{$A, p, q - 1$}
100-
\STATE \CALL{Quicksort}{$A, q + 1, r$}
101-
\ENDIF
102-
\ENDPROCEDURE
103-
\PROCEDURE{Partition}{$A, p, r$}
104-
\STATE $x = A[r]$
105-
\STATE $i = p - 1$
106-
\FOR{$j = p$ \TO $r - 1$}
107-
\IF{$A[j] < x$}
108-
\STATE $i = i + 1$
109-
\STATE exchange
110-
$A[i]$ with $A[j]$
93+
<pre id="quicksort" style="display:hidden;">
94+
% This quicksort algorithm is extracted from Chapter 7, Introduction to Algorithms (3rd edition)
95+
\begin{algorithm}
96+
\caption{Quicksort}
97+
\begin{algorithmic}
98+
\PROCEDURE{Quicksort}{$A, p, r$}
99+
\IF{$p < r$}
100+
\STATE $q = $ \CALL{Partition}{$A, p, r$}
101+
\STATE \CALL{Quicksort}{$A, p, q - 1$}
102+
\STATE \CALL{Quicksort}{$A, q + 1, r$}
111103
\ENDIF
112-
\STATE exchange $A[i]$ with $A[r]$
113-
\ENDFOR
114-
\ENDPROCEDURE
115-
\end{algorithmic}
116-
\end{algorithm}</textarea>
117-
```
118-
119-
### API
120-
Assume the pseudocode to be rendered is in a `<pre>` DOM element:
121-
```html
122-
<pre id="hello-world-code" style="display:hidden;">
123-
\begin{algorithmc}
124-
\PRINT \texttt{'hello world'}
125-
\end{algorithmc}
104+
\ENDPROCEDURE
105+
\PROCEDURE{Partition}{$A, p, r$}
106+
\STATE $x = A[r]$
107+
\STATE $i = p - 1$
108+
\FOR{$j = p$ \TO $r - 1$}
109+
\IF{$A[j] < x$}
110+
\STATE $i = i + 1$
111+
\STATE exchange
112+
$A[i]$ with $A[j]$
113+
\ENDIF
114+
\STATE exchange $A[i]$ with $A[r]$
115+
\ENDFOR
116+
\ENDPROCEDURE
117+
\end{algorithmic}
118+
\end{algorithm}
126119
</pre>
127120
```
128121

129-
To render the above code as a HTML element and append to a parent DOM element,
130-
call `pseudocode.render`:
131-
```js
132-
var code = document.getElementById("hello-world-code").textContent;
133-
var parentEl = document.body;
134-
var options = {
135-
lineNumber: true
136-
};
137-
pseudocode.render(code, parentEl, options);
138-
```
122+
#### Step 4 &middot; Render the element using pseudocode.js
123+
Insert the following Javascript snippet at the end of your document:
139124

140-
To generate a string of rendered HTML, call `pseudocode.renderToString`:
141-
```js
142-
var code = document.getElementById("hello-world-code").textContent;
143-
var options = {
144-
lineNumber: true
145-
};
146-
var htmlStr = pseudocode.renderToString(code, options);
147-
console.log(htmlStr);
125+
```html
126+
<script>
127+
var elem = document.getElementById("hello-world-code");
128+
var options = {
129+
lineNumber: true
130+
};
131+
pseudocode.render(elem.textContent, elem.parentNode, options);
132+
</script>
148133
```
149134

150135

@@ -279,7 +264,7 @@ var DEFAULT_OPTIONS = {
279264
```
280265

281266
## Build and Test
282-
Pseudocode.js is written in JavaScript and built with [Node.js](https://nodejs.org).
267+
pseudocode.js is written in JavaScript and built with [Node.js](https://nodejs.org).
283268
So, make sure you have Node.js installed before building pseudocode.js.
284269

285270
To compile the project on Ubuntu Linux, run the following commands in terminal:
@@ -294,7 +279,7 @@ Then, open one of the sample documents:
294279
- `build/katex-samples.html`, or
295280
- `build/mathjax-v2-samples.html`, or
296281
- `build/mathjax-v3-samples.html`
297-
in your favourite browser to check if the algorithms are typeset correctly.
282+
in your favorite browser to check if the algorithms are typeset correctly.
298283

299284

300285
## Author
@@ -305,6 +290,6 @@ and I am the current maintainer of this project.
305290
Suggestions, bug reports and pull requests are most welcome.
306291

307292
## Acknowledgement
308-
Pseudocode.js is partially inspired by [KaTeX](http://khan.github.io/KaTeX/).
293+
pseudocode.js is partially inspired by [KaTeX](http://khan.github.io/KaTeX/).
309294
Thanks Emily Eisenberg([@xymostech](https://github.com/xymostech))
310-
and other contributers for building such a wonderful project.
295+
and other contributors for building such a wonderful project.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pseudocode",
3-
"version": "2.0",
3+
"version": "2.0.0",
44
"author": {
55
"name": "Saswat Padhi",
66
"email": "saswat.sourav@gmail.com",
@@ -13,7 +13,7 @@
1313
"url": "git://github.com/SaswatPadhi/pseudocode.js"
1414
},
1515
"files": [
16-
"pseudoCode.js",
16+
"pseudocode.js",
1717
"src/"
1818
],
1919
"devDependencies": {

static/katex-samples.html.template

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<head>
55
<meta charset="utf-8">
6-
<title>Pseudocode.js Samples with KaTeX</title>
6+
<title>pseudocode.js Samples with KaTeX</title>
77

88
<!-- Setup KaTeX -->
99
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.css"
@@ -149,19 +149,19 @@
149149
\end{algorithmic}
150150
\end{algorithm}
151151
</pre>
152-
<script type="text/javascript">
153-
var testBasics = document.getElementById("test-basics").textContent;
154-
pseudocode.render(testBasics, document.body, {
152+
<script>
153+
var basicsEl = document.getElementById("test-basics");
154+
pseudocode.render(basicsEl.textContent, basicsEl.parentNode, {
155155
lineNumber: false,
156156
noEnd: true
157157
});
158-
var testCodes = document.getElementById("test-codes").textContent;
159-
pseudocode.render(testCodes, document.body, {
158+
var codesEl = document.getElementById("test-codes");
159+
pseudocode.render(codesEl.textContent, codesEl.parentNode, {
160160
lineNumber: false,
161161
noEnd: false
162162
});
163-
var testExamples = document.getElementById("test-examples").textContent;
164-
pseudocode.render(testExamples, document.body, {
163+
var examplesEl = document.getElementById("test-examples");
164+
pseudocode.render(examplesEl.textContent, examplesEl.parentNode, {
165165
lineNumber: true,
166166
noEnd: false
167167
});

static/mathjax-v2-samples.html.template

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<head>
55
<meta charset="utf-8">
6-
<title>Pseudocode.js Samples with MathJax</title>
6+
<title>pseudocode.js Samples with MathJax</title>
77

88
<!-- Setup MathJax -->
99
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS_CHTML'>
@@ -157,19 +157,19 @@
157157
\end{algorithmic}
158158
\end{algorithm}
159159
</pre>
160-
<script type="text/javascript">
161-
var testBasics = document.getElementById("test-basics").textContent;
162-
pseudocode.render(testBasics, document.body, {
160+
<script>
161+
var basicsEl = document.getElementById("test-basics");
162+
pseudocode.render(basicsEl.textContent, basicsEl.parentNode, {
163163
lineNumber: false,
164164
noEnd: true
165165
});
166-
var testCodes = document.getElementById("test-codes").textContent;
167-
pseudocode.render(testCodes, document.body, {
166+
var codesEl = document.getElementById("test-codes");
167+
pseudocode.render(codesEl.textContent, codesEl.parentNode, {
168168
lineNumber: false,
169169
noEnd: false
170170
});
171-
var testExamples = document.getElementById("test-examples").textContent;
172-
pseudocode.render(testExamples, document.body, {
171+
var examplesEl = document.getElementById("test-examples");
172+
pseudocode.render(examplesEl.textContent, examplesEl.parentNode, {
173173
lineNumber: true,
174174
noEnd: false
175175
});

static/mathjax-v3-samples.html.template

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<head>
55
<meta charset="utf-8">
6-
<title>Pseudocode.js Samples with MathJax</title>
6+
<title>pseudocode.js Samples with MathJax</title>
77

88
<!-- Setup MathJax -->
99
<script>
@@ -157,19 +157,19 @@
157157
\end{algorithmic}
158158
\end{algorithm}
159159
</pre>
160-
<script type="text/javascript">
161-
var testBasics = document.getElementById("test-basics").textContent;
162-
pseudocode.render(testBasics, document.body, {
160+
<script>
161+
var basicsEl = document.getElementById("test-basics");
162+
pseudocode.render(basicsEl.textContent, basicsEl.parentNode, {
163163
lineNumber: false,
164164
noEnd: true
165165
});
166-
var testCodes = document.getElementById("test-codes").textContent;
167-
pseudocode.render(testCodes, document.body, {
166+
var codesEl = document.getElementById("test-codes");
167+
pseudocode.render(codesEl.textContent, codesEl.parentNode, {
168168
lineNumber: false,
169169
noEnd: false
170170
});
171-
var testExamples = document.getElementById("test-examples").textContent;
172-
pseudocode.render(testExamples, document.body, {
171+
var examplesEl = document.getElementById("test-examples");
172+
pseudocode.render(examplesEl.textContent, examplesEl.parentNode, {
173173
lineNumber: true,
174174
noEnd: false
175175
});

static/pseudocode.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import url('https://cdn.jsdelivr.net/npm/katex@0.10.1/dist/katex.min.css');
1+
@import url('https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.css');
22

33
@font-face {
44
font-family: KaTeX_Typewriter_Replace;
@@ -42,7 +42,7 @@
4242
text-indent: 0;
4343
font-size: 1em;
4444
}
45-
.ps-root .mjx-chtml {
45+
.ps-root .MathJax_CHTML, .ps-root .MathJax {
4646
text-indent: 0;
4747
font-size: 1em !important;
4848
}

0 commit comments

Comments
 (0)