diff --git a/docs/runlatex-codemirror.js b/docs/runlatex-codemirror.js new file mode 100644 index 0000000..825abab --- /dev/null +++ b/docs/runlatex-codemirror.js @@ -0,0 +1,486 @@ +// runlatex.js for TeXLive.net and Overleaf +// Copyright 2020 2021 David Carlisle +// MIT Licence + +// set here but local versions can be redefined after +// loading this file + +// runlatex configuration object +var runlatex={} + +runlatex.texts ={ + "Open in Overleaf": "Open in Overleaf", + "TeXLive.net": "run at TeXLive.net", // or "run latex" or whatever + "Delete Output": "Delete Output", + "Compiling PDF": "Compiling PDF", + // The following not used on learnlatex.org + "edit": "edit", + "copy": "copy", + "Added Code": "Added code", + "End Added Code": "End Added code", + "Top Caption": "Edit and run this example:" +} + +runlatex.editorlines=100; +runlatex.adddefaultpreamble=false; +runlatex.adddefaultengine=false; +runlatex.usecaptions=false; +runlatex.minrunlines=0; +runlatex.completionsURI=""; + +// debug by using https://httpbin.org/post +// set to null to omit from interface +runlatex.latexcgiURI="https://texlive.net/cgi-bin/latexcgi"; +runlatex.overleafURI="https://www.overleaf.com/docs"; + +// per page setup +runlatex.preincludes={}; + +// Disable all use of cookies +// No cookies are set by this file even when true. +runlatex.usecookies=true; + +// end of configuration + +var editors=[]; + +const noeditregex = /^\s*[/%#\*]+ *!TEX.*[^a-zA-Z]noedit *(\n|$)/i; +const norunregex = /^\s*([/%#\*]+ *!TEX.*[^a-zA-Z]none *|[^% \t\\][^\\]*)(\n|$)/i; +const commentregex = / %.*/; +const engineregex = /% *!TEX.*[^a-zA-Z](((pdf|xe|lua|u?p)?latex(-dev)?)|context|(pdf|xe|lua|u?p)?tex) *\n/i; +const returnregex = /% *!TEX.*[^a-zA-Z](pdfjs|pdf|log|make4ht|latexml|lwarp) *\n/i; +const makeindexregex = /% *!TEX.*[^a-zA-Z]makeindex( [a-z0-9\.\- ]*)\n/ig; + +var packageregex = [ + [ /\\includegraphics/, "\\usepackage[demo]{graphicx}\n"], + [ /\\begin{equation|align|gather|flalign/,"\\usepackage{amsmath}\n" ], + [ /tikz|pgf/, "\\usepackage{tikz}\n" ], + [ /fancy/, "\\usepackage{fancyhdr}\n" ], + [ /addplot|axis/, "\\usepackage{pgfplots}\n" ], + [ /hyper|href|bookmark|\\url/, "\\usepackage{hyperref}\n" ], + [ /\\newcolumntype/, "\\usepackage{array}\n" ], + [ /listing/, "\\usepackage{listings}\n" ], + [ /\\blind/, "\\usepackage{blindtext}\n" ], + [ /\\lipsum/, "\\usepackage{lipsum}\n" ], + [ /color/, "\\usepackage{xcolor}\n" ], + [ /pspicture/, "\\usepackage{pstricks}\n" ] +]; + + +var latexcompetions=""; + + +var customCompleter = { + getCompletions: function(editor, session, pos, prefix, callback) { + var startToken = session.getTokenAt(pos.row, pos.column).value; + if (startToken.startsWith("\\")){ + var cmplts=[]; + var s=0; + for (let pkg in latexcompletions) { + var cs=latexcompletions[pkg]; + s=s-1; + for(let i=0;i"; + p[i].parentNode.insertBefore(f2, p[i].nextSibling); + } + if(runlatex.overleafURI){ + // overleaf + var o = document.createElement("button"); + o.innerText=runlatex.texts["Open in Overleaf"]; + o.setAttribute("class","llbutton"); + o.setAttribute("onclick",'openinoverleaf("pre' + i + '")'); + p[i].parentNode.insertBefore(o, p[i].nextSibling); + var f=document.createElement("span"); + f.innerHTML="
"; + p[i].parentNode.insertBefore(f, p[i].nextSibling); + } + } + if(runlatex.adddefaultpreamble) { + pretext=pretext.replace(/^[ \t\u00A0]+$/gm,''); + } + p[i].textContent=pretext.replace(/\s+$/,''); + if(rlacetheme.startsWith('ace')) { + p[i].style.height="1em"; // force redisplay in Opera zoom + ace.config.set('basePath', 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12') ; + editor = ace.edit(p[i]); + editor.setTheme(rlacetheme); + editor.getSession().setMode(acemode); + editor.setOption("minLines",runlatex); + editor.setOption("maxLines",runlatex.editorlines); + editor.setShowPrintMargin(false); + if(runlatex.completionsURI != ""){ + langTools=ace.require("ace/ext/language_tools"); + langTools.setCompleters([customCompleter]); + editor.setOptions({ + enableBasicAutocompletion: true, + enableLiveAutocompletion: true + }); + } + editor.resize(); + } else { + var pcont = p[i].textContent; + p[i].textContent=""; + editor =CodeMirror(p[i],{ + lineNumbers: true, + mode: 'stex', + tabSize: 2, + value: pcont + }); + } + editors["pre" + i]=editor; + } + } + } +} + + +function addinput(f,n,v) { + var inp=document.createElement("input"); + inp.setAttribute("type","text"); + inp.setAttribute("name",n); + inp.value =encodeURIComponent(v); + f.appendChild(inp); +} + +function addinputnoenc(f,n,v) { + var inp=document.createElement("input"); + inp.setAttribute("type","text"); + inp.setAttribute("name",n); + inp.value =v; + f.appendChild(inp); +} + +function addtextarea(f,n,v) { + var inp=document.createElement("textarea"); + inp.setAttribute("type","text"); + inp.setAttribute("name",n); + inp.textContent=v; + f.appendChild(inp); +} + +function openinoverleaf(nd) { + var fm = document.getElementById('form-' + nd); + fm.innerHTML=""; + var p = document.getElementById(nd); + var t = editors[nd].getValue(); + + var engv=rldefaultengine; + var eng=t.match(engineregex); + if(runlatex.adddefaultpreamble) { + if(t.indexOf("\\documentclass") == -1 && ( eng == null)) { + t=generatepreamble(t,editors[nd]); + } + } + if(eng != null) { + engv=eng[1].toLowerCase(); + if(engv == "pdftex" || engv == "luatex" || engv == "xetex" || engv == "ptex" || engv == "uptex") { + addinput(fm,"main_document","document.tex"); + } + } + addinput(fm,"encoded_snip[]","\n" + t); + addinput(fm,"snip_name[]","document.tex"); + if(typeof(runlatex.preincludes) == "object") { + if(typeof(runlatex.preincludes[nd]) == "object") { + var incl=runlatex.preincludes[nd]; + for(prop in incl) { + if(editors[prop]==null) { + addinput(fm,"encoded_snip[]",document.getElementById(prop).textContent); + } else { + addinput(fm,"encoded_snip[]",editors[prop].getValue()); + } + addinput(fm,"snip_name[]",incl[prop]); + } + } + } + if(eng != null) { + if(engv.indexOf("platex") != -1 || engv.indexOf("ptex") != -1 || engv=="tex") { + addinput(fm,"encoded_snip[]","$latex = '" + engv + "';\n$bibtex = 'pbibtex';\n$dvipdf = 'dvipdfmx %O -o %D %S';"); + addinput(fm,"snip_name[]","latexmkrc"); + engv="latex_dvipdf"; + } else if(engv == "pdftex" || engv == "luatex" || engv == "xetex") { + addinput(fm,"encoded_snip[]","$pdflatex = '" + engv + "';"); + addinput(fm,"snip_name[]","latexmkrc"); + engv=rldefaultengine; + } + + } + addinput(fm,"engine",engv); + fm.submit(); +} + +function copytoclipboard(nd){ + var p = document.getElementById(nd); + var nn=document.createElement("textarea"); + nn.value=p.innerText; + document.body.appendChild(nn); + nn.select(); + document.execCommand("copy"); + document.body.removeChild(nn); +} + + +function allowedit(nd){ + var p = document.getElementById(nd); + p.contentEditable="true"; + p.setAttribute("spellcheck","false"); + p.innerHTML=p.innerText; + p.style.border="solid thin green"; +} + +function deleteoutput(nd){ + var b = document.getElementById('del-' + nd); + var ifr = document.getElementById(nd + 'ifr'); + b.parentNode.removeChild(b); + ifr.parentNode.removeChild(ifr); +} + +function generatepreamble(t,e) { + e.navigateFileStart(); + if(t.match(/koma|KOMA|addsec|\\scr|scrheadings/)){ + e.insert("\n% " + runlatex.texts["Added Code"] + "\n\\documentclass{scrartcl}\n"); + } else { + e.insert("\n% " + runlatex.texts["Added Code"] + "\n\\documentclass{article}\n"); + } + for(var i=0;i 0) { + c_start = document.cookie.indexOf(c_name + "="); + if (c_start != -1) { + c_start = c_start + c_name.length + 1; + c_end = document.cookie.indexOf(";", c_start); + if (c_end == -1) { + c_end = document.cookie.length; + } + return unescape(document.cookie.substring(c_start, c_end)); + } + } + return ""; +} + +function rlSetReturn(n) { + createCookie('runlatex-return',n,100); +} + +var rldefaultreturn=getCookie('runlatex-return'); +if(rldefaultreturn=="") rldefaultreturn="pdfjs"; + +function rlSetEngine(n) { + createCookie('runlatex-engine',n,100); +} + +var rldefaultengine=getCookie('runlatex-engine'); +if(rldefaultengine=="") rldefaultengine="pdflatex"; + + +var rlacetheme=getCookie('runlatex-acetheme'); +//if(rlacetheme=="") rlacetheme="ace/theme/textmate"; +if(rlacetheme=="") rlacetheme="codemirror/theme/monokai"; + +function rlAllowCookies() { + createCookie('runlatex-cookies',"true",100); + window.location.reload(false); +} + +function rlDeleteCookies() { + createCookie('runlatex-cookies',"",-999); + createCookie('runlatex-return',"",-999); + createCookie('runlatex-engine',"",-999); + createCookie('runlatex-acetheme',"",-999); + window.location.reload(false); +} + +var rlallowcookies=getCookie('runlatex-cookies')=="true"; + +window.addEventListener('load', llexamples, false); diff --git a/docs/test-codemirror.html b/docs/test-codemirror.html new file mode 100644 index 0000000..051f1a3 --- /dev/null +++ b/docs/test-codemirror.html @@ -0,0 +1,173 @@ + + + + LaTeX CGI tests + + + + + + + + + + + + + + +
+ +Site index page
+Site Settings page + +
+ + + +

codemirror Tests

+ + +

Engine Parameter

+

By default pdftex, or xelatex if fontspec is used.

+
+
+  \documentclass{article}
+  \usepackage{iftex}
+  \newcommand\test[1]{\par\expandafter#1\string#1: true\fi}
+  \begin{document}
+   
+  \ttfamily
+  \test\ifpdftex
+  \test\ifluatex
+  \test\ifxetex
+  \test\ifptex
+  \test\ifuptex
+  \end{document}
+
+
+ +

lualatex

+
+
+%!TEX lualatex
+  \documentclass{article}
+  \usepackage{iftex}
+  \newcommand\test[1]{\par\expandafter#1\string#1: true\fi}
+  \begin{document}
+  \ttfamily
+  \test\ifpdftex
+  \test\ifluatex
+  \test\ifxetex
+  \test\ifptex
+  \test\ifuptex
+  \end{document}
+
+
+ + + +

Marathi

+
+
+%!TeX xelatex  
+  \documentclass{article}
+  \usepackage{marathi}
+  \begin{document}
+हा मजकूर देवनागरी लिपीत स्वरांशचिन्हांसह लिहिण्यात आला आहे.
+  \end{document}
+
+
+ + + +

Makeindex[] Parameter

+

Multiple !TEX makeindex may be used, each sets a makeindex[] + parameter in the form submission.

+
+
+
+% !TEX makeindex document
+% !TEX makeindex -s nomencl.ist -o document.nls -t document.nlg document.nlo
+
+\documentclass[oneside,12pt]{article}
+
+\usepackage{makeidx}
+\makeindex
+
+\usepackage{nomencl}
+\makenomenclature
+
+\begin{document}
+
+Testing\index{testing} nomenclature\index{nomenclature}
+\[
+E = mc^2
+\]
+
+\nomenclature{$E$}{Energy}
+\nomenclature{$m$}{Mass}
+\nomenclature{$c$}{Speed of Light}
+
+\begin{center}
+\begin{minipage}[t]{.45\linewidth}
+\printnomenclature    
+  \end{minipage}\hfill
+  \begin{minipage}[t]{.45\linewidth}
+\renewenvironment{theindex}{%
+\section*{\indexname}}{}
+\printindex
+  \end{minipage}
+\end{center}
+
+\end{document}
+
+
+ +