PureLatex
Summary: Make latex available in wiki edits without additional wrapping markup
Version: linuxtex.php 2006-12-15
Prerequisites: a working latex installation, dvipng
Status: Work in continous progress
Maintainer: ThomasP
Categories:
Votes:
>><<
(This project is connected to the Cookbook.LinuxTex recipe.)
This page is dedicated to making latex syntax available to the wiki editor without extra (or only minimal) wrapping markup. The main motivation for this is to simplify the import and export of once-created latex code, as well as to ease the way for the general scientific user who is accustomed with latex but most often not with wiki particularities. In the end it should be possible to prepare a document collaboratively over the web (with minimal wiki knowledge), and take the result to print media (without any conversion barrier etc.).
This project has just taken off to the phase of "work in progress". Below I have listed the issues that I liked to be implemented most:
- displaying inline and block equations, but now with the typical latex syntax as introductory elements, i.e.
$...$
and$$...$$
- interpreting \ref and \label (might need a section counter besides an equation counter)
- in particular allow forward references
- interpreting \begin{align}...\end{align} (a.s.o.) environments
- interpreting \section
- interpreting \cite etc., and generating a bibliography
As the main syntax elements of both latex and the wiki language do not (seem to) overlap, I have started implementing the above features by just adding appropriate custom markup to the linuxtex.php, for example:
Markup('$$','directives','/\\$\\$(.*?)\\$\\$/e',"blockformula('$1')"); // for block latex
If this should not suffice in future, some parser switch of the form similar to
>>green<<
could be implemented, named according to
>>latex<<
(for switching to pure latex mode. Anything that follows is in a format that can be directly used for compiling with latex.)>>wikitext<<
(for switching back to the default wiki parser.)
CHANGELOG
- (done) displaying inline and block equations with the typical latex syntax as introductory elements, i.e.
$...$
and$$...$$
- (done) interpreting \begin{align*}...\end{align*} environments, including ones spanning multiple lines
- (done) interpreting \section, \subsection, \subsubsection
- (done) interpreting \emph{}
- (pending) interpreting \ref and \label
- (pending) interpreting \cite etc., and generating a bibliography
Markup rules implemented until now
This is what I have currently in use in my linuxtex.php:
// pattern to match #$DoubleBrackets['/\\{\\$(.*?)\\$\\}/e'] = "inline('$1')"; #$DoubleBrackets['/\\{\\%(.*?),(.*?)\\%\\}/e'] = "tex('$1', '$2')"; #$DoubleBrackets['/EQ\((.*?)\)/e'] = "ref('$1')"; #Markup('{$','directives','/\\{\\$(.*?)\\$\\}/e',"inline('$1')"); // for inline latex ###Markup('{$ ','directives','/\\{\\$\\ (.*?)\\ \\$\\}/e',"inline('$1')"); // for inline latex Markup('{$$','directives','/\\{\\$\\$(.*?)\\$\\$\\}/e',"blockformula('$1')"); // for block latex (without reference) // removal of the rule above strangely results in the '$$' rule being left uninterpreted :( // The following rules recognize $x$, $\theta$, $$\int_\omega f(x) = 1$$ and $$ \int_\omega f(x) = 1 $$, but // avoid $ x $ or $x $. (This would be too easily mixed up with variables in code snippets.) Markup('$2','directives','/\\$([^\ ])\\$/e',"inline('$1')"); // for one-character inline latex Markup('$$','directives','/\\$\\$(.*?)\\$\\$/e',"blockformula('$1')"); // for block latex (without reference) Markup('$','directives','/\\$([^\ ].*?[^\ ])\\$/e',"inline('$1')"); // for inline latex Markup('{%','directives','/\\{\\%(.*?),(.*?)\\%\\}/e',"tex('$1','$2')"); // for formula with reference Markup('\begin{align*}','fulltext','/\\\\begin\\{align\\*\\}(.*?)\\\\end\\{align\\*\\}/sei',"blockformula('$1')"); // for formulas inside align environment, still unfinished Markup('/EQ','directives','/EQ\((.*?)\)/e',"ref('$1')"); //for references to formulas // interpret \section{} etc.: Markup('\section', 'block', '/\\\\section\\{(.*?)\\}/e', "'<:block,1><h2'.PSS('>$1</h').'2>'"); Markup('\subsection', 'block', '/\\\\subsection\\{(.*?)\\}/e', "'<:block,1><h3'.PSS('>$1</h').'3>'"); Markup('\subsubsection', 'block', '/\\\\subsubsection\\{(.*?)\\}/e', "'<:block,1><h4'.PSS('>$1</h').'4>'"); // interpret \emph{}: Markup('\emph', 'inline', "/\\\\emph\\{(.*?)\\}/", '<em>$1</em>');
ThomasP June 24, 2007, at 08:11 AM