Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,323 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env node | ||
|
||
const fs = require('fs') | ||
const path = require('path') | ||
const child_process = require("child_process"); | ||
let input = fs.readFileSync(0, 'utf-8') | ||
|
||
input=replaceLiteral(input, "€€") | ||
input=replaceLiteral(input, "€") | ||
|
||
console.log(input) | ||
|
||
const pandocFilterPath = path.join(__dirname, "pandoc-filter.js") | ||
|
||
let result = child_process.spawnSync("pandoc", ["-t", "latex", "-f", "markdown+lists_without_preceding_blankline+hard_line_breaks", "-s", "--filter", pandocFilterPath], { input: input }).stdout | ||
|
||
console.log(String(result)) | ||
|
||
fs.writeFileSync("input.tex", String(result)) | ||
|
||
function replaceLiteral(input, literal){ | ||
let position=input.indexOf(literal) | ||
let first=true | ||
while(position!=-1){ | ||
input=input.substring(0, position)+"\n\`\`\`"+(first?"asciimath"+String(literal.length):"")+"\n"+input.substring(position+2, input.length) | ||
first=!first | ||
position=input.indexOf("€€") | ||
} | ||
return input | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "caoutchouc", | ||
"version": "0.1.0", | ||
"description": "Caoutchouc compiler", | ||
"main": "index.js", | ||
"directories": { | ||
"test": "tests" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/corollari/caoutchouc.git" | ||
}, | ||
"keywords": [ | ||
"latex" | ||
], | ||
"author": "corollari", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/corollari/caoutchouc/issues" | ||
}, | ||
"homepage": "https://github.com/corollari/caoutchouc#readme", | ||
"dependencies": { | ||
"pandoc-filter-promisified": "^0.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env node | ||
|
||
const pandoc = require('pandoc-filter-promisified') | ||
const AsciiMath2Latex = require('./lib/ASCIIMathTeXImg.js') | ||
const { CodeBlock, RawBlock } = pandoc | ||
|
||
const HEADER = "asciimath" | ||
|
||
pandoc.stdio(action) | ||
|
||
async function action(elt, pandocOutputFormat, meta) { | ||
if (elt.t === `CodeBlock`) { | ||
// console.warn(JSON.stringify(elt, null, 4)); | ||
const [headers, content] = elt.c | ||
|
||
const literalLength = getAsciiMathLiteral(headers) | ||
if(literalLength === 0) return | ||
|
||
const literal = literalLength==2?"$$":"$" | ||
|
||
let newContent = literal+AsciiMath2Latex(content)+literal | ||
|
||
return RawBlock('latex', newContent) | ||
} | ||
} | ||
|
||
function getAsciiMathLiteral(headers) { | ||
const [_, classes, keyValuePairs] = headers | ||
|
||
if(classes.includes(HEADER+"1")) return 1 | ||
if(classes.includes(HEADER+"2")) return 2 | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
€€ | ||
1/2*alpha | ||
€€ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
\PassOptionsToPackage{unicode=true}{hyperref} % options for packages loaded elsewhere | ||
\PassOptionsToPackage{hyphens}{url} | ||
% | ||
\documentclass[]{article} | ||
\usepackage{lmodern} | ||
\usepackage{amssymb,amsmath} | ||
\usepackage{ifxetex,ifluatex} | ||
\usepackage{fixltx2e} % provides \textsubscript | ||
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex | ||
\usepackage[T1]{fontenc} | ||
\usepackage[utf8]{inputenc} | ||
\usepackage{textcomp} % provides euro and other symbols | ||
\else % if luatex or xelatex | ||
\usepackage{unicode-math} | ||
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase} | ||
\fi | ||
% use upquote if available, for straight quotes in verbatim environments | ||
\IfFileExists{upquote.sty}{\usepackage{upquote}}{} | ||
% use microtype if available | ||
\IfFileExists{microtype.sty}{% | ||
\usepackage[]{microtype} | ||
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts | ||
}{} | ||
\IfFileExists{parskip.sty}{% | ||
\usepackage{parskip} | ||
}{% else | ||
\setlength{\parindent}{0pt} | ||
\setlength{\parskip}{6pt plus 2pt minus 1pt} | ||
} | ||
\usepackage{hyperref} | ||
\hypersetup{ | ||
pdfborder={0 0 0}, | ||
breaklinks=true} | ||
\urlstyle{same} % don't use monospace font for urls | ||
\setlength{\emergencystretch}{3em} % prevent overfull lines | ||
\providecommand{\tightlist}{% | ||
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} | ||
\setcounter{secnumdepth}{0} | ||
% Redefines (sub)paragraphs to behave more like sections | ||
\ifx\paragraph\undefined\else | ||
\let\oldparagraph\paragraph | ||
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}} | ||
\fi | ||
\ifx\subparagraph\undefined\else | ||
\let\oldsubparagraph\subparagraph | ||
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}} | ||
\fi | ||
|
||
% set default figure placement to htbp | ||
\makeatletter | ||
\def\fps@figure{htbp} | ||
\makeatother | ||
|
||
|
||
\date{} | ||
|
||
\begin{document} | ||
|
||
$$\frac{{1}}{{2}}\cdot\alpha$$ | ||
|
||
\end{document} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Header | ||
This is a basic equation €1+2*sqrt(2)-pi+alpha/(3.2-1)€ | ||
Display math: | ||
€€ | ||
sum 1 | ||
€€ | ||
More complex things can be done with latex: | ||
$$x\overset{\Bbb{R}}{+} y=x\overset{\Bbb{Q}}{+} y$$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```asciimath2 | ||
1/2*alpha | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
\PassOptionsToPackage{unicode=true}{hyperref} % options for packages loaded elsewhere | ||
\PassOptionsToPackage{hyphens}{url} | ||
% | ||
\documentclass[]{article} | ||
\usepackage{lmodern} | ||
\usepackage{amssymb,amsmath} | ||
\usepackage{ifxetex,ifluatex} | ||
\usepackage{fixltx2e} % provides \textsubscript | ||
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex | ||
\usepackage[T1]{fontenc} | ||
\usepackage[utf8]{inputenc} | ||
\usepackage{textcomp} % provides euro and other symbols | ||
\else % if luatex or xelatex | ||
\usepackage{unicode-math} | ||
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase} | ||
\fi | ||
% use upquote if available, for straight quotes in verbatim environments | ||
\IfFileExists{upquote.sty}{\usepackage{upquote}}{} | ||
% use microtype if available | ||
\IfFileExists{microtype.sty}{% | ||
\usepackage[]{microtype} | ||
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts | ||
}{} | ||
\IfFileExists{parskip.sty}{% | ||
\usepackage{parskip} | ||
}{% else | ||
\setlength{\parindent}{0pt} | ||
\setlength{\parskip}{6pt plus 2pt minus 1pt} | ||
} | ||
\usepackage{hyperref} | ||
\hypersetup{ | ||
pdfborder={0 0 0}, | ||
breaklinks=true} | ||
\urlstyle{same} % don't use monospace font for urls | ||
\setlength{\emergencystretch}{3em} % prevent overfull lines | ||
\providecommand{\tightlist}{% | ||
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} | ||
\setcounter{secnumdepth}{0} | ||
% Redefines (sub)paragraphs to behave more like sections | ||
\ifx\paragraph\undefined\else | ||
\let\oldparagraph\paragraph | ||
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}} | ||
\fi | ||
\ifx\subparagraph\undefined\else | ||
\let\oldsubparagraph\subparagraph | ||
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}} | ||
\fi | ||
|
||
% set default figure placement to htbp | ||
\makeatletter | ||
\def\fps@figure{htbp} | ||
\makeatother | ||
|
||
|
||
\date{} | ||
|
||
\begin{document} | ||
|
||
\frac{{1}}{{2}}\cdot\alpha | ||
|
||
\end{document} |