-
-
Save porky11/19a61bee718aba8e10ec129c28032946 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env scopes | |
Example usage: | |
$ scd <File> <somepdfviewer> | |
There has to be a file called <File>.scd | |
The format of the file needs to be a valid scopes file with only symbols, strings and lists. | |
This will generate <File>.tex and <File>.pdf | |
When the argument <somepdfviewer> is supplied, the pdf viewer will automatically open the generated pdf file. | |
You need to have installed texlive (the pdflatex command). | |
using import utils.files | |
let count args = | |
launch-args; | |
assert | |
count >= 2 | |
"Count not greater equal 2" | |
let filename open = | |
string (args @ 2) | |
count >= 3 | |
let document-data = | |
list-load (filename .. ".scd") | |
do | |
let file = | |
File (filename .. ".tex") "w" | |
'write-string file | |
""""\documentclass[a4paper]{article} | |
\begin{document} | |
\setlength{\oddsidemargin}{-1cm} | |
\setlength{\hsize}{18cm} | |
\setlength{\vsize}{24cm} | |
\setlength{\topmargin}{-2cm} | |
\pagenumbering{gobble} | |
fn generate-document (file document-data indent first) | |
if (empty? document-data) | |
return; | |
else | |
let element rest = | |
decons document-data | |
let T = ('typeof element) | |
match T | |
case Symbol | |
'write-string file | |
""""\setlength{\parindent}{0ex} | |
'write-string file | |
.. "\\setlength{\\leftskip}{" (tostring (4 * indent)) "ex}" | |
'write-string file "\\textbf{" | |
#if first | |
'write-string file "\\item " | |
'write-string file | |
element as Symbol as string | |
'write-string file | |
""""}\par | |
case string | |
'write-string file | |
""""\setlength{\parindent}{0ex} | |
'write-string file | |
.. "\\setlength{\\leftskip}{" (tostring (4 * indent)) "ex}" | |
'write-string file | |
element as string | |
'write-string file | |
""""\par | |
case list | |
this-function file | |
element as list | |
indent | |
true | |
default | |
error | |
.. "data format type " | |
tostring T | |
" not expedted" | |
this-function file rest | |
? first (indent + 1) indent | |
false | |
_; | |
generate-document file | |
document-data as list | |
indent = 0 | |
false | |
'write-string file | |
"""" | |
\end{document} | |
include "unistd.h" | |
include "stdlib.h" | |
include "sys/wait.h" | |
inline s (string) | |
string as rawstring | |
inline exec (program ...) | |
let program = | |
s program | |
execlp program program ((va-join (va-map s ...)) null) | |
let pid = | |
fork; | |
if (pid == 0) | |
exec "pdflatex" (filename .. ".tex") | |
elseif (pid == -1) | |
error "pdflatex failed" | |
else | |
wait (reftoptr (local i32 pid)) | |
if open | |
let program = | |
string (args @ 3) | |
exec program (filename .. ".pdf") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment