Extension talk:Wiki2LaTeX

Math tags added
I needed to convert the $$$$ tag, to use formulas on exporting latex documents, so I added some very simple code:

in w2lConfig.php I added the line

$w2l_tags['math']        = array('w2l_mwext_support', "math");

and, in w2LatexUtil.php, into the w2l_mwext_support class I added the function function math($input, $argv, &$parser, $mode = 'wiki') { $output = "\n\begin{math}\n"; $output .= trim($input)."\n"; $output .= "\end{math}\n"; return $output; } just copied and modified from the "pre" function

and it worked! Hope it can be useful for others. :)

(and hope of being in the correct place to post my hints...)
 * I added your code to the corefiles, so the next version will support $$$$ natively. Thanks! HG 16:41, 20 August 2007 (UTC)

Image Processing
I have implemented a simple solution for processing of internal images. It searches for the filename in the images/ directory and copies it to an image directory under the tmp/tmp-123... directory. You can add my little helper class with the following steps:

First of all you need to add a few lines to function internalLinkHelper in w2lParser.php before the line // First, check for |: if ( (stripos($link, "Bild:") === 0) or (stripos($link, "Image:") === 0) ) { $link = str_replace('Bild:', '', $link); $link = str_replace('Image:', '', $link); return "". $link. ""; }

Then you need to include my class file at the top of w2lExporter.php: require_once('w2lImages.php');

In w2lExporter.php you need to edit function w2l_unknown_action</tt> to process the images. I added the following line $parsed = w2lImages::processImages($parsed, $mytemp); to the sections where $action</tt> is w2lpdf</tt> or w2ltex</tt> right behind these lines: $parsed = $parser->parse($to_parse); $mytemp = $helper->path;

And this is my little class file w2lImages.php</tt>:

<?php define('W2L_ImageDir', "Bilder"); define('W2L_ImageTitle', "Abbildung");

class w2lImages {

public static function processImages($parsed, $mytemp) {       $matches = array; $matchCount = preg_match_all('/(.*)<\/IMAGE>/', $parsed, $matches); if ($matchCount > 0) {               $cntr = 0; foreach ($matches[1] as $link) {                       $imgTag = $matches[0][$cntr]; $links = explode("|", $link); $imgFileName = $links[0]; if (strpos($imgFileName, 'jpg') != false) {                               $imgFile = shell_exec("find ./images -name " . $imgFileName); if ($imgFile) {                                       $imgFiles = explode("\n", $imgFile); foreach ($imgFiles as $if) {                                               if (strlen($if) > 0 && strpos($if, "thumb") == false) $imgFile = $if; }                                       if (!file_exists($mytemp. "/" . W2L_ImageDir)) {                                               mkdir($mytemp . "/" . W2L_ImageDir, 0777); }                                       $copied = copy($imgFile, $mytemp . "/" . W2L_ImageDir . "/" . $imgFileName); if ($copied) {                                               $imgCaption = (isset($links[1])) ? $links[1] : W2L_ImageTitle. " " . $cntr; $imgLatex = '\begin{figure}[htb]'. "\n"; $imgLatex .= '\centering'. "\n"; $imgLatex .= '\includegraphics[width=\textwidth]{'. $imgFileName. '}' . "\n"; $imgLatex .= '\caption{'. $imgCaption. '}' . "\n"; $imgLatex .= '\label{fig:'. W2L_ImageTitle. $cntr. '}' . "\n"; $imgLatex .= '\end{figure}'. "\n"; $parsed = str_replace($imgTag, $imgLatex, $parsed); }                                       else {                                               $parsed = str_replace($imgTag, "Image could not be copied: " . $imgFileName, $parsed); }                               }                        }                        else {                               $parsed = str_replace($imgTag, "Image is not a JPG: " . $imgFileName, $parsed); }                       $cntr++; }               return $parsed; }       else {               return $parsed; } }

} ?>

This will result in images included like this: \begin{figure}[htb] \centering \includegraphics[width=\textwidth]{ImageName.jpg} \caption{Abbildung 1} \label{fig:Abbildung1} \end{figure}

Any comments are welcome ;) http://blog.stefan-macke.de

-

Hi Stefan,

I've cut down your code to this snippet that does case-insensitive matching for image: tags + supports image size in centimeters: Inside internalLinkHelper in w2lParser.php:

if(preg_match("/(?i)image:/",$link, $matches)) { $parts = preg_split("/\|/", $link); $imagename = str_replace($matches[0], '', array_shift($parts)); $imgwidth = "10cm"; foreach ($parts as $part) { if (preg_match("/\d+px/", $part)) continue; if (preg_match("/(\d+cm)/", $part, $widthmatch)) { $imgwidth = $widthmatch[1]; continue; }

if (preg_match("/thumb|thumbnail|frame/", $part)) continue; if (preg_match("/left|right|center|none/", $part)) continue; $caption = trim($part); }               $title = Title::makeTitleSafe( NS_IMAGE, $imagename ); $file = new Image( $title ); $file->loadFromFile; $imagepath = $file->getImagePath; $title = $file->getTitle->getText; return "\\begin{center} \\resizebox{".$imgwidth."}{!}{\includegraphics}\\\\ \\textit\end{center}\n";

Given a tag like: it will output LaTeX like: \begin{center} \resizebox{20cm}{!}{\includegraphics{/var/www/mediawiki/images/a/a1/Colombes.jpg}}\\ \textit{Colombes, France}\end{center}

I think there's a lot of good solutions on this page, now we only need Hans-Georg to choose one for the next release.

Cheers, Ole Dahle

namespace problems
If you're not using custom namespaces the extension will stop since it tries to search $wgExtraNamespaces. Is that LaTeX namespace required? If so - for what? --Flominator 10:32, 14 August 2007 (UTC)
 * Solved, see front page. Anyway it should better print what's wrong instead of simply crashing. --Flominator 10:49, 14 August 2007 (UTC)
 * Yeah, the extension should print an error. It's a little mistake, as the extra namespace is only required, if you are using the pdf-export-feature. Will be fixed in v.0.5, which is not too far away. Sorry for the inconvenience. HG 12:16, 14 August 2007 (UTC)

Problem with 0.6.1
Both, the dev-version and the one from Google produce this message: Fatal error: Call to undefined method Image::getPath in C:\XAMPP\htdocs\itswiki\extensions\w2l\w2lParser.php on line 1025 regards, --Flominator 05:52, 14 September 2007 (UTC)
 * Works fine for me. Might be an issue regarding the filename or you're not using Mediawiki 1.11, which is required to run W2L v.0.6 and above due to several changes to local files which were introduced in Mediawikiversions since 1.9. --HG 09:48, 14 September 2007 (UTC)
 * I go this same error with MW1.10, so upgraded to 1.11 as suggested, now new error when trying to export pdf:

Fatal error: Call to a member function getTimestamp on a non-object in /var/lib/mediawiki-1.11.0/extensions/wiki2latex/w2lExporter.php on line 365
 * The relevant section of w2lExporter.php</tt> is

357                // Get Template-Vars... 358    359                 $template_vars = $w2l_vars; 360                $template_vars = $helper->getTemplateVars($to_parse); 361      //If title was not set by a tag, use page title 362                // Put some special variables in the template vars 363    364                 $rev = Revision::newFromTitle($wgTitle); 365                $date = $wgLang->timeanddate( wfTimestamp(TS_MW, $rev->getTimestamp), true ); 366                if(!in_array("Title", $template_vars)) { 367                        $template_vars['Title']  = $title; 368                }    369                 $template_vars['revision timestamp'] = $date; 370                $template_vars['revision user'] = $rev->getUserText; 371                $template_vars['revision id'] = $rev->getId; 372                $template_vars['page id'] = $helper->getArticleId;
 * So $rev</tt> must be null, is it allowed to be, and if so, does this just need an exception test? Any suggestions? I had no problem with the update.php</tt> on the database. Hoogs 15:54, 21 September 2007 (UTC)
 * That's odd. I can't reproduce that error. In case you don't use the template tags, which are defined by these lines, you can put the lines 364-372 into a comment. Might not be the best way, but should work. But I added a Null</tt>-check to the current code. So it should be fixed in w2l 0.6.2. --HG 17:36, 21 September 2007 (UTC)
 * Thanks. Actually there is another problem that may be the cause.  I'd set up address redirection in apache2 for MW1.10, but now for some reason although articles are displayed properly in MW1.11, when I go to the edit tab, the edit page for "Index.php" comes up, for any page.  This probably affects your code too, I'll post when resolved. Hoogs 01:57, 22 September 2007 (UTC)

0.6.1 on Ubuntu server
Running Ubuntu 6.06.1 LTS LAMP server running MW1.11 (upgraded from MW1.10) with the following extensions:


 * Pdf, prints a page as pdf, Thomas Hempel
 * Cite, adds tags for citations, Ævar Arnfjörð Bjarmason
 * ParserFunctions, enhance parser with logical functions, Tim Starling
 * StringFunctions (version 1.9.3)

Editing Index.php
Pages were displaying ok, but upon editing, a generic "Editing Index.php" page would come up. Turns out there is a simple fix, adding:

$wgUsePathInfo = false;

to LocalSettings.php</tt>

Wiki2LaTeX extension installation and testing
The following problems/fixes relate to the pdf export functionality only which was the quickest "so what can this extension do?" test.

Originally, I had put the extension in a directory named extensions/wiki2latex</tt> but the path extensions/w2l</tt> is hardwired into the php (it may be worthwhile emphasising this a bit more), so corrected.

These warnings were displayed: Warning: mkdir [function.mkdir]: Permission denied in /var/lib/mediawiki-1.11.0/extensions/w2l/w2lExporter.php on line 691

Warning: chmod [function.chmod]: No such file or directory in /var/lib/mediawiki-1.11.0/extensions/w2l/w2lExporter.php on line 692

Warning: file_put_contents(extensions/w2l/tmp/tmp-1190454669-678688419/Main.tex) [function.file-put-contents]: failed to open stream: No such file or directory in /var/lib/mediawiki-1.11.0/extensions/w2l/w2lExporter.php on line 402

Warning: chdir [function.chdir]: No such file or directory (errno 2) in /var/lib/mediawiki-1.11.0/extensions/w2l/w2lExporter.php on line 413

The directory extensions/w2l</tt> must be writeable so this was fixed (lazily) with


 * 1) chmod -R a+w /extensions/w2l

Maybe worth mentioning permissions on the extension directory tree. This error came up in the latex log:

LaTeX Error: File `utf8x.def' not found.

This was fixed in ubuntu with


 * 1) aptitude install latex-ucs

It may be worth starting a list of dependencies. For some wiki pages, even though there was no fatal error in the latex log and Main.{tex,pdf}</tt> etc. seemed ok, the extension would display the message

w2lParser::getContentByTitle: Artikel existiert nicht: Vorlage:Date

Google translated:

w2lParser:: getContentByTitle: Article does not exist: Collecting main: DATE

I couldn't resolve this. The generated pdf seemed to pick up  $$...$$ </tt> perfectly. However 0.6.1 did not display these correctly:

Basic stuff I really need
 * <tt> ... </tt> (have used these to centre equations)
 * tables

Nice-to-haves
 * (currently nil, I haven't tested sufficiently yet)

I have never really found a decent converter and this looks promising so congratulations and many thanks!! I now use my mediawiki as a primary documentation system at work, so if we can build the bridge wiki -> latex/pdf this will be an amazing tool. Hoogs 11:25, 22 September 2007 (UTC)
 * The error saying <tt>"Artikel existiert nicht: Vorlage:Date"</tt> means, that a template could not be found. Will be fixed soon. Regarding the issue with <tt> $$$$ </tt> I'd be interested what exactly does not display right, as that should be fine for long time now. <tt> ... </tt> support is on the todo-list. --HG 17:57, 23 September 2007 (UTC)
 * Sorry, misunderstanding, math tags work fine, I have changed grammar above to make that clearer. What about tables? I think you would need table conversion to be able to say you have complete basic-level functionality. Hoogs 23:32, 23 September 2007 (UTC)
 * Tables are supported. At least simple ones without 'rowspan'-ing or 'colspan'-ing. You just need to add a small attribute, which is documented at Extension talk:Wiki2LaTeX/Development/w2lParser.php. I hope it works for you.--HG 07:03, 24 September 2007 (UTC)
 * Awesome, thanks for the heads up! Hoogs 11:00, 24 September 2007 (UTC)

file path
First off this is one the coolest most useful extensions and almost everything is working great (it's very fool-proof I suppose). But I can't get it to output the pdf in the temp folder. I ran the (pdflatex -interaction=nonstopmode Main.tex) line from w2lConfig file in cmd, and all the tasks got completed one after another (I have MiKTeX installed on my XP of course) except at the end it says: No pages of output. Transcript written on pdflatex.log. entering extended mode ! I can't find file `Main.tex'. <*> Main.tex Please type another input file name ! Emergency stop. <*> Main.tex ! ==> Fatal error occurred, no output PDF file produced! Transcript written on texput.log. It seems that everything's fine except that it can't find the Main.tex

I actually tried running the pdflatex -interaction=nonstopmode Main.tex line with a full path to Main.tex like C:\server\..\temp\temp-123\Main.tex and the cmd stopped because the MiKTeX wanted to download an additional package, it actually never downloaded the package but that's irrelevant.

Basically is there any documentation I could find or things I should know setting up the TeX software for w2l and vice versa? This far the only mention of tex I've seen is on the latex tab saying: "needs working tex-installation on server!". Where can I find more? 354d 09:51, 28 September 2007 (UTC)
 * You could try to install the missing package via the package manager of MikTeX. Basically the tex-instalation does not need to be configured as most should run out of the box. But there are some things you can do to check if there are problems with w2l:
 * Locate the tmp/some_strange_numbers/-folder and check if the file <tt>Main.tex</tt> is existing.
 * if the file exists, change to the directory in the command line and run <tt>pdflatex Main.tex</tt>. (If it doesn't exist, somehow w2l can't write to the tmp-folder)
 * Check if pdflatex prints out any warning or error-message while compiling the texfile.
 * If you can't locate the error, please post the complete log here. Maybe something else is causing the problem.
 * --HG 14:32, 28 September 2007 (UTC)

\multirow, tabulary instead of tabularx
Hi HG +Co., thanks for this extremely promising extension. I found out (using still w2l-0.6.2 on a Suse 10.2) that for my purposes the package "tabulary" (in combination with package "multirow") gives nicer tables than "tabularx". If you want to test my version (not elegant at all and ways too complicated -but I am learning-) do the following: after if ( !defined('MEDIAWIKI') ) die; add the line require_once('doTabulary.inc.php'); add an "if"-argument in maskMwSpecialChars($str) ); if(!preg_match("/}{\*}{/", $str))    $str = strtr($str, $chars); and cut externalTableHelper down to private function externalTableHelper( $matches ) { $t = trim($matches[1]); //in w2l-0.7.0: $t = trim( $matches ); $t = doTabulary($t); return $t; } \usepackage{tabulary} \usepackage{multirow} <?php function getSpanDetails($spantype, $array_with_span_arguments){ //for $spantype use "rowspan" or "colspan" //this function finds the lines containing a rowspan resp. a colspan argument. //$span_details[0] is a subarray with the span containing line numbers (the last line of the array first) as keys //and the size of the "span" as its value //$span_details[1] is a subarray with the span containing line numbers again as keys and the content of the "spanned" cell as value  $grep_string = "/.*".$spantype."=\"[0-9]+\"/";  $match_string = "/".$spantype."=\"([0-9]+)\"\s\|\s(.*)/";  $idx = preg_grep($grep_string, $array_with_span_arguments); $content = array; foreach($idx as $key => $value){ preg_match_all($match_string, $value, $spanline); $idx[$key] = $spanline[1][0]; $content[$key] = $spanline[2][0]; } $span_details= array($idx, $content); return $span_details; } function evalRowkeys($exploded_str){ //array rowkeys contains position "{|" (!not quite right, but necessary), row separators "|-", table end of exploded string (= array) $rowkeys = array_keys($exploded_str, '|-'); //w2l-0.7.0: $table_end = array_search('|}', $exploded_str); $table_end = array_search('|\\}', $exploded_str); $rowkeys[] = $table_end; $table_begin = preg_grep("/^(!.*)|(^\|[^+].*)/", $exploded_str); reset($table_begin); array_unshift($rowkeys, key($table_begin)); $rowkeys[0] -= 1; //hack: all the others start BEFORE the first column return $rowkeys; } function actualRowsize($rowkeys){ $actual_rowsize = array; for ( $i = 1; $i < count($rowkeys); ++$i){ $actual_rowsize[$i-1] = ($rowkeys[$i] - $rowkeys[$i-1]-1); } return $actual_rowsize; } function doTabulary($t) { $splitstr = explode("\n", $t); foreach($splitstr as $key => $cell) $splitstr[$key] = trim($cell); //after each colspan="x"-argument: insert (x-1) colspandummies $colspan = getSpanDetails("colspan", $splitstr); $colspan_idx = $colspan[0]; $colspan_content = $colspan[1]; krsort($colspan_idx); krsort($colspan_content); foreach($colspan_idx as $key => $value){ $temp_fill = array_fill(0, ($value-1), '| §?colspandummy?§ '); array_splice($splitstr, $key + 1, 0, $temp_fill); if(strpos($splitstr[$key], '| ') === 0) $splitstr[$key] = '| \multicolumn{'.$value.'}{c|}{'.$colspan_content[$key].'}'; if(strpos($splitstr[$key], '! ') === 0)     $splitstr[$key] = '| \multicolumn{'.$value.'}{c|}{\textbf{'.$colspan_content[$key].'}}'; } //in each row that is in reach of an upstream rowspan-argument: insert a rowdummy // in case there are not enough column-entries in a row up to the rowdummy, fill it up with "row_more_dummies" $rowspan = getSpanDetails("rowspan", $splitstr); $rowspan_idx = $rowspan[0]; $numrowspans = count($rowspan_idx); for($x = 0; $x < $numrowspans; ++$x){ $rowkeys = evalRowkeys($splitstr); $actual_rowsize = actualRowsize($rowkeys); $rowspan = getSpanDetails("rowspan", $splitstr); $rowspan_idx = $rowspan[0]; $rowspan_idx_keys = array_keys($rowspan_idx); $i = 0; while ($rowspan_idx_keys[0] > $rowkeys[$i+1]) ++$i; $rowspan_position_in_row = $rowspan_idx_keys[0] - $rowkeys[$i]; $fill_one = array_fill(0, 1, '| ?§rowdummy§? '); for($k = ($rowspan_idx[$rowspan_idx_keys[0]]-1); $k > 0; --$k){ if($actual_rowsize[$i+$k] >= $rowspan_position_in_row) array_splice($splitstr, ($rowkeys[$i+$k] + $rowspan_position_in_row), 0, $fill_one); else{ $fill_more = array_fill(0, $rowspan_position_in_row - $actual_rowsize[$i+$k]-1, '| ?§row_more_dummies§? '); $fill_more = array_merge($fill_more, $fill_one); array_splice($splitstr, $rowkeys[$i+$k] + $actual_rowsize[$i+$k] + 1, 0, $fill_more); }     $splitstr[$rowspan_idx_keys[0]] = str_replace('rowspan', 'r_span', $splitstr[$rowspan_idx_keys[0]]); } }  $rowkeys = evalRowkeys($splitstr); $actual_rowsize = actualRowsize($rowkeys); //how many cols does the largest row have? $temp = ($actual_rowsize); rsort($temp); $maxcolrow = $temp[0]; //now we know, also needed later for the "|Y|Y|..." in the LaTeX table declaration //Now fill up the table, every row will have $maxcolrow colums then: krsort($actual_rowsize); for ($i = count($actual_rowsize)-1; $i >= 0; --$i){ $tofillupmax = $maxcolrow - $actual_rowsize[$i]; if($tofillupmax > 0){ $fillup_array = array_fill(0, $tofillupmax, '| '); array_splice($splitstr, $rowkeys[$i+1], 0, $fillup_array); }   else {} } $rowspan = getSpanDetails("r_span", $splitstr); $rowspan_idx = $rowspan[0]; $rowspan_content = $rowspan[1]; foreach($rowspan_idx as $key => $value){ if(strpos($splitstr[$key], '| ') === 0) $splitstr[$key] = '| \multirow{'.$value.'}{*}{'.$rowspan_content[$key].'}'; if(strpos($splitstr[$key], '! ') === 0)     $splitstr[$key] = '| \multirow{'.$value.'}{*}{\textbf{'.$rowspan_content[$key].'}}'; } $rowkeys = evalRowkeys($splitstr); //end of row: -> \cline : for($j = 1; $j < count($rowkeys)-1; ++$j){ $clinestr = '\\\\ '; for($i = $rowkeys[$j-1]+1; $i < $rowkeys[$j]; ++$i){ $clinecount = $i - $rowkeys[$j-1]; if(!preg_match("/(rowdummy)|(multirow)/", $splitstr[$i])) $clinestr = $clinestr	.'\\cline{'.$clinecount.'-'.$clinecount.'} '; else{} }	   $splitstr[$rowkeys[$j]] = $clinestr; } //remove colspandummies $rem_colspandummy = preg_grep("/colspandummy/", $splitstr); krsort($rem_colspandummy); foreach($rem_colspandummy as $key => $value) array_splice($splitstr, $key, 1); //some conversions etc. ... foreach($splitstr as $key => $cell){ if(strpos($cell, '! ') === 0)     $splitstr[$key] = str_replace('! ', "& \\textbf{", $cell).'}'; if(strpos($cell, '|+ ') === 0) $splitstr[$key] = str_replace('|+ ', "\multicolumn{".$maxcolrow."}{|c|}{ ", $cell)." }\\\\ \hline "; if(strpos($cell, '| ') === 0) $splitstr[$key] = str_replace('| ', '& ', $cell); //w2l-0.7.0: if(strpos($cell, '|}') === 0) if(strpos($cell, '|\\}') === 0) //w2l-0.7.0: $splitstr[$key] = str_replace('|}', "\\\\ \hline \end{tabulary} \\\\", $cell); $splitstr[$key] = str_replace('|\\}', "\\\\ \hline \end{tabulary} \\\\", $cell); if(strpos($cell, '{|') === 0) $splitstr[$key] = "\\newline \\\\     \\newcolumntype{Y}{>{\centering\arraybackslash}C}      \setlength\extrarowheight{4pt} \setlength\\tabcolsep{2pt} \setlength\\tymin{30pt}      \begin{tabulary}{\\textwidth}{".str_repeat('|Y', $maxcolrow)."|} \hline"; else {} } $newline = preg_grep("/\\\\\s/", $splitstr); foreach($newline as $key => $value){ $splitstr[$key + 1] = str_replace('& ', '', $splitstr[$key + 1]); } $splitstr = str_replace('?§rowdummy§? ', '', $splitstr); $splitstr = str_replace('?§row_more_dummies§? ', '', $splitstr); //here is a hack needed with "vspace", because in "tabulary" colored fonts somehow produce a vertical offset, //thereby enlarging rowheight unneccessarily: $splitstr = str_replace('<span style="color:', '\vspace{-8pt}{\color{', $splitstr); $splitstr = str_replace('">', '}', $splitstr); $splitstr = str_replace(' ', '}', $splitstr); $splitstr = preg_replace('/\'\'\'(.*)\'\'\'/', '\\textbf{$1}', $splitstr); foreach($splitstr as $key => $cell){ if(strpos($cell, '|') === 0) $splitstr[$key] = str_replace('|', '& ', $cell); else{} } $t = implode("\n", $splitstr); return $t; }
 * in w2lParser.php:
 * in the preamble of your LaTeX-template add:
 * and finally save the following lines as "doTabulary.inc.php" (without my test-table, of course): !changes needed for w2l-0.7.0 as comments!

/* My test table (copy & paste into your wiki): ?>

...what do you think about it?

Cheers --Michael 15:23, 30 October 2007 (UTC)
 * Hi Michael! I tried to activate your tablecode but somehow it does not work. But I will look into it. It could take a while because I'm quite busy at the moment. Maybe your code can optionally integrated into W2L, since there are some more ways to write LaTeX-tables. We will see. --HG 18:33, 30 October 2007 (UTC)
 * Hi HG! But it's NOT because "matches" in externalTableHelper( $matches ) from 0.6.2 (the version I used in my description) is an array whereas in 0.7 a string is handed over, right? I will check the posted code again, maybe I created a copy/paste error? --Michael 19:14, 30 October 2007 (UTC)
 * OOPS, a bit more serious than a simple copy/paste mistake: It couldn't work because the "*" in \multirow{x}{*}{text} was not "protected". For a fix, function maskMwSpecialChars in w2lParser.php has to be modified, see description above. Sorry! --Michael 11:13, 31 October 2007 (UTC)
 * Hi Michael! I have been busy over the last weeks so I could not really answer or try any of your proposed changes. But now I could and I really like what your code manages. Especially the support for colspan is great. I suggest, that we change your code in a way that it can be integrated into the existing event-system of W2L. That should be possible from the next version on, which I hope to get ready in early december. It will primarily be a bugfix release. stay tuned. --HG 15:24, 18 November 2007 (UTC)

Interwiki support
Wiki2LaTeX seems to not be able to handle interwikis. This is the output: Wiki2LaTeXParser::internalLinkHelper: Caution: Namespace could not be found: pt:About this Site.

Is it possible to support it? Nuno Tavares 17:55, 12 January 2008 (UTC)
 * Hi Nuno, it is possible to support interwikilinks, and it is on the list for a future relese of this extension. --HG 14:06, 24 March 2008 (UTC)

Errors Generating Tables
Thank you for a nice plugin which does many things so nicely.

I have the following difficulty using tables. For a table, the Main.tex has a line like this:

\begin{tabularx}{\linewidth}{}\hline

and manually compiling I get an error message like "! Package array Error: Empty preamble: `l' used. See the array package documentation for explanation." Furthermore, when it finishes compiling, the tables look rather ugly, with each cell on its own line.

However, if I edit Main.tex directly, adding "ll" for my two-column table, so that:

\begin{tabularx}{\linewidth}{ll}\hline

and run pdflatex manually, then everything looks fine.

First of all, am I doing something wrong (perhaps in my wiki markup to explicitly say the number of columns)? Second, how does one control how tables are formatted, in case I don't like the defaults? Thank you. Comfortably Paranoid 05:25, 6 October 2008 (UTC)


 * Hi. Tables are the most difficult part of the Wiki->LaTeX/PDF Conversion as the syntax is quite different. LaTeX requires a string stating the alignment within the table cells. Some information has been posted here. In short: You have to add a latexfmt-attribute to every table that will be converted. I hope that someday I will find a way to fill in these informations via script, but that is not too simple. I hope this helps a bit. --HG 16:41, 12 October 2008 (UTC)


 * Thank you for that information and link, it is working better now. Comfortably Paranoid 09:28, 13 October 2008 (UTC)

Problem with this extension
I have installed this package succesfully. I have picked an article and clicked on "latex/pdf" It has redirected to some option page. I have select text file as my output. It gives a messsage that creating "Main.tex" But i am not able to see that file. Is it created in any other location?? Help needed. Thx...
 * Hi! You should see a link to Main.tex. This function was broken in v.0.9 and 0.9.1. If you are using one of these version, please update to 0.9.2. This should fix the problem. Hope this helps, bye --HG 21:09, 8 December 2008 (UTC)

Problem PDF Export
I have installed the last Version of Wiki2LaTeX successfully. The Function PDF-Export produces following message:

LaTeX failed to create your file. Most often this error occurs when your LaTeX-Code requests packages which are not part of your LaTeX- Distribution: Main.tex, Main.log

and the following message in a box:

TempPath: /tmp/w2ltmp-1231940199-591212464 Command: pdflatex -interaction=batchmode Main.tex == Run #1 == ERROR: PDF file could not be created.

What can I do to solve the problem?

-- Kdvzis 13:43, 14 January 2009 (UTC)

I had the same problem using MW 1.13 and Wiki2LateX on a Windows XP Pro System. My problem was that the folder of the pdflatex.exe was not in the PATH environment variable.

-- Calamuc (talk) 16:38, 23 December 2012 (UTC) What should i write in the PATH variable?

Support for ?
I didn't see any explicit support for wiki. It would be natural to convert this to \begin{quotation} or \begin{quote}. It was easy enough to edit w2lParse.php and add two lines:

$replacing = array(                         &#39; &#39;  => &#39;\begin{center}&#39;,                        &#39; &#39; => &#39;\end{center}&#39;,                        &#39; &#39;  => &#39;\begin{quotation}&#39;,                        &#39; &#39; => &#39;\end{quotation}&#39;,

How about putting that in the next version? --Comfortably Paranoid 08:33, 11 May 2009 (UTC)


 * Hi, that makes perfectly sense. I added blockquote-support. Thanks for pointing this missing html-tag out. bye --HaGe-K 13:31, 11 May 2009 (UTC)
 * Great! Glad to hear it. --Comfortably Paranoid 22:18, 11 May 2009 (UTC)

Wiki2LaTeX and TinyMCE
I am using the TinyMCE RTE to format my articles. I also have successfully installed the Wiki2LaTeX extension. But in the generated PDF i get all the HTML Tags generated by TinyMCE. So my idea is to convert the HTML code to wiki markup before sending it to the LaTeX Compiler - there are some php-Classes or JavaScripts on the Web that attend this job.

Can anyone tell where i can find the content (in a php-object) of the exported Wikipage after submitting the Export?

Thanks a lot & best regards!

Labelled Equations
Is labelled equations from the CrossReference Extension supported? One would think something like:

<equation id="eq:blabla">... -> \begin{equation}\label{eq:blabla}...\end{equation}

and also:

<xr id="eq:blabla">(whatever)</xr> -> \ref{eq:blabla}

This way we would be able to use numbered equations in a uniform way in wiki and latex.

Does this exist? If not should I invest the time to write it? Of course, if somebody who knows the internals could add it fast, it would be easier --Gurcani 15:03, 1 September 2009 (UTC)

inline queries from semantic mediawiki and dynamic page lists
Is there a simple way to parse inline queries from Extension:Semantic_MediaWiki and Extension:DynamicPageList_(third-party) before exporting to latex? Thanx for any help! Tomy 7:33 pm 05 October 2009.

Tables and latexfmt
In wiki2latex 0.11, I'm putting something like latexfmt="|r|l|Y|" into tables to control the formatting. But it seems like the Parser is ignoring this --- it puts in |Y|Y|Y|, which would be a nice default, but I expected that I should be able to override the default with explicit latexfmt. A much older version of wiki2latex accepted latexfmt.

Is this a feature or a bug? Comfortably Paranoid 06:35, 13 October 2010 (UTC)

Math export is not working
Version w2l-0.11, default settings,

input:

Test
test1 test2 test3. $$ t'=\frac{t-(V/c^2)x}{\sqrt{1-V^2/c^2}}, $$ test4 test5 test6.

output: \section{Test} test1 test2 test3.

test4 test5 test6.

X-romix 10:00, 8 November 2010 (UTC)
 * Didn't check 0.11, but works for me with pre-0.10. Ilya Voyager 13:17, 8 November 2010 (UTC)
 * I also have problems with math in 0.11.   That is a bug that needs to be fixed.  As a temporary workaround, I found that by replacing <tt>contrib/math.php</tt> with a pre-0.11 version, then it starts working again.   Comfortably Paranoid 22:16, 8 November 2010 (UTC)

I've solve this problem but I don't remember how. :-) Working set (for 1.16.0) with some modifications I've upload here: http://x-romix.narod.ru/w2l_x-romix_for_mw_1_16_0.zip X-romix 10:34, 5 March 2011 (UTC)

Custom namespace
Hi, perhaps it would be useful to register the namespace used by this extension on this page. Cheers --kgh 21:52, 22 November 2010 (UTC)
 * That sounds like a good idea.  The current installation instructions amount to "find an empty namespace".   With a registered namespace XXX then XXX would be placed in the source code, and the user wouldn't have to change it?   Comfortably Paranoid 23:26, 22 November 2010 (UTC)
 * Every time I come across an extension requiring a namespace I make aware of this page, since not every developer might know about it. Moving the setting of the namespace into code is definitely more user friendly. Perhaps in hypothetically very rare cases (namespace collision) the user might be forced to change it, but this should then not be a problem for her or him. However, the closer the number gets to 100 the more likely is a collision. Just go for it. :) --kgh 23:47, 22 November 2010 (UTC) PS In other words: The answer to your question is Yes. --kgh 23:50, 22 November 2010 (UTC)

So then, I'll make a proposal. The namespace should be 250 with constant NS_W2L.

The following two lines can appear in wiki2latex.php (rather than LocalSettings.php, following the model of DeleteQueue): define("NS_W2L", 250); $wgExtraNamespaces[NS_W2L] = "LaTeX"; Then, the only one line must be added to LocalSettings.php for installation.

To register the selection, the following should be added to Extension namespace registration

=== Wiki2LaTeX === * <tt>250</tt> LaTeX: (constant: NS_W2L)

— Comfortably Paranoid 02:09, 23 November 2010 (UTC)


 * Sounds good to me. Great! Cheers --kgh 16:28, 23 November 2010 (UTC)
 * I just recently stumbled over that possibility (and this discussion here, somehow I haven't been notified over changes here on this discussion page :. The next version will incorporate this setting - even though this means breaking all existing installations and forcing them to move all templates. But the gained comfort in installing W2L seems to be worth it. --HaGe-K 13:23, 23 February 2011 (UTC)
 * A small update on this one: I decided to use another number than 250/251. There are issues concerning the upgrade process. Please do not use the chosen numbers (400/401) on your wiki. That would mean, that your templates become inaccessible :( (Happened to me when I tried this). --HaGe-K 13:34, 23 February 2011 (UTC)

PDF not created and no errors generated.
I am getting the following error when trying to generate the PDF. LaTeX failed to create your file. Most often this error occurs when your LaTeX-Code requests packages which are not part of your LaTeX-Distribution: Main.tex, Main.log Creating file Main.tex with 1863 Bytes Command: pdflatex -interaction=batchmode Main Path: C:\Windows\TEMP\\w2ltmp-1297275162-1859

Run #1
<w2l_pdf_not_created>

The interesting thing though is when I go to the directory I find the Main.tex but no Main.log or Main.pdf. Also when I open the Main.tex with TeXworks and select the Play button with the pdfLaTeX+MakeIndex+BibTeX option the PDF gets created.

I am also able to create a PDF when I run the following from the command line. pdflatex -interaction=nonstopmode Main.tex Also works with the following from the command line. pdflatex -interaction=batchmode Main


 * I don't know about Windows, but if you were on Linux, a possible cause of this problem is that the user which runs the web server (a user named apache) cannot run pdflatex.  This could be because the pdflatex is not in the users path, other permissions not being set correctly, or some other special file required by pdflatex is not available (like the message says).   As I recall, I debugged problems like this by piping the output of the pdflatex command to a file (by hacking the wiki2latex php source code), then looking at that file for errors.  Solutions included making a soft link to pdflatex in a directory where apache user could see it, and manually copying some needed file.
 * It would be nice if wiki2latex had some kind of debugging mode for things like this. (this debugging mode would: 1. report whether or not pdflatex was in the path 2. Give all the output from pdflatex, this might require getting both stdout and stderr. These things could be reported on the web page).   Comfortably Paranoid 09:29, 15 February 2011 (UTC)


 * More notes.
 * I tried to adjust the permissions on the executable but that did not resolve the issue. After running procmon I found the following

"4:59:48.4830741 PM	cmd.exe	3144	QueryDirectory	C:\Windows\Temp\w2ltmp-1298498388-6430\pdflatex -interaction=batchmode Main.*	NO SUCH FILE	Filter: pdflatex -interaction=batchmode Main.*"
 * Another note, I also added pdflatex as an environmental variable. Still did not work.

Zmanc 17:03, 23 Feburary 2011 (EST)


 * Well, it may not help much since I'm on linux, but here is the output from my log file (created by checking "show log file" on the latex/pdf tab):

Creating file Main.tex with 27821 Bytes Command: /usr/local/texlive/2009/bin/i386-linux/pdflatex -interaction=batchmode Main Path: /tmp/w2ltmp-1298875569-511705824
 * While not knowing much about Windows, it looks like in your "QueryDirectory" line, that pdflatex is actually in the Temp/w2ltmp directory.   Is that right?   It's too bad it doesn't say which file is no such file.    Comfortably Paranoid 06:50, 28 February 2011 (UTC)


 * Update I changed what location the temp directory was writing to thinking it might be a permissions issue. This did not resolve the issue. I am getting the same error as before, only to another directory. Also @Comfortably Paranoid it is using the temp directory.

Zmanc 14:03, 1 March 2011 (EST)

Notes on Debugging LaTeX Compiler Problems and xelatex
Recently, I've been trying to set up xelatex instead of pdflatex as the compiler. I finally solved it.

In the process, I had to debug compiler problems. Since the user Zmanc above was also having problems, I made a short list of general debugging tips that I found useful (at least on Linux):


 * 1) latex compilers produce both stdout and stderr.   Seeing the stderr might be useful.   In w2lConfig.php, modify the command as below.  This will put two files stdout and stderr into the tmp directory which can be inspected.
 * 2) * $w2lConfig['ltx_command'] = 'ulimit -a >> debug_file ; /usr/local/bin/pdflatex -interaction=batchmode %file% > stdout 2> stderr';
 * 3) cd into the tmp directory and run the compiler as sudo -u apache pdflatex Main.tex, you can see what is happening
 * 4) If you are really desperate, you can add commands to  w2lLaTeXCompiler.php to output debugging info in the web browser.   Inside function runLaTeX(...) add lines like:
 * 5) * $msg .= "User: ".wfShellExec("whoami ; pwd ; ulimit -a");

For getting xelatex to work, by looking at the stderr, I found that xelatex was getting an out-of-memory error. By using ulimit -a, indeed there was a virtual memory limit for child processes. Much to my surprise, I found that not the operating system, not httpd/apache, but MediaWiki itself was setting a limit at 102400 kB. By adding $wgMaxShellMemory = 0 to my MediaWiki LocalSettings file, the memory limit was lifted and xelatex could compile. Comfortably Paranoid 10:22, 4 May 2011 (UTC)

sub / sup parsing
I've add into w2lParser.php this text to process upper and lower indexes:

Test case:


 * m2
 * H2O

--X-romix 10:24, 5 March 2011 (UTC)
 * I added them to W2L. Thank you very much for pointing out these missing html tags. --95.114.246.47 10:39, 6 March 2011 (UTC)
 * Unfortunatly \textsuperscript{} is not working with GrindEQ, sample  from  is working. X-romix 08:30, 9 March 2011 (UTC)

Using PDF export with 'proTeXt'
Hello

I've installed LaTeX on the server, along with the W2L extension. It is functioning to the extent that you can browse to a page, click the LaTeX tab and download the TeX file etc. The only thing that I can't get to work is the PDF part. I realise that you require pdfTeX for this to work - however is it possible to get the extension to work with proTeXt, which was included as part of MiKTeX?

The pdfTeX site states the following: "Those not wanting to upgrade pdfTeX alone are strongly advised to get a version of their TeX distribution which has it, e.g. of TeX Live or MikTeX."

So it seems like it should work. Thanks. Csf90 11:47, 22 December 2011 (UTC)


 * Getting the PDF part to work can be tricky, because an external program, the latex complier must be called, and many things can go wrong. proTeXt is a distribution for Windows. I presume you already modified the $w2lConfig['ltx_command']   variable?
 * Even though they are for linux, some of my debugging notes might point you in the right direction, if you are comfortable with hacking shell scripts and php.   Comfortably Paranoid 16:42, 22 December 2011 (UTC)

Fatal error: Call to undefined method SiteStats::admins
Hi, I installed wiki2latex on mediawiki 1.18.2 and I see Fatal error: Call to undefined method SiteStats::admins in /var/www/mediawiki/extensions/w2l/w2lCore.php on line 556 I checked the -code and as it tells correctly there is no function or method   anymore, but a static accessible variable. So it might work replacing  (line 1) just by   (line 3): --Andreas P. 19:33, 26 April 2012 (UTC) as of MW 1.19 this has changed again :-( so a programmers work around might be the following quick-fix (I’m not sure if the static access to MagicWord::$mVariableIDs['numberofadmins'] is availible in MW 1.18, 1.17) --Andreas P. 02:32, 5 May 2012 (UTC)

Fatal error: Call to undefined method SiteStats::admins Revisited
I tried the above fix on 1.19.2 and it failed. MagicWord only returns a properties array relating to the magic word itself as far as I can see, and the MagicWord::$mVariableIDs['numberofadmins'] actually throws up and complains about an undefined index 'numerofadmins'. Anyway, on searching around the code of 1.15.4 and 1.19.2 I discovered that since at least v 1.15 there has been a single method SiteStats::numberingroup for delivering a count of all members in a specified group. Here's a mini fix using that info.

Ksalt (talk) 09:34, 19 September 2012 (UTC)

No options page after clicking latex/pdf tab
I've installed the latest version of the extension for media wiki 1.19.2. On Special:Version and in preferences, wiki2latex shows up as being installed. Also, I have a "latex/pdf" tab when logged in. However, upon clicking the "latex/pdf" tab, the page redirects to a blank page. Nothing happens.

Any suggestions? (I've followed all install directions precisely.) I am using Firefox 16.0.1 and running on Ubuntu version 12.04 LTS.

-
 * Same problem but with CentOS 6.3. Your web server error log will probably show a PHP error. It seems there is a small bug with the w2lCore.php file. Modify 'extensions/w2l/w2lCore.php' line 556 from:


 * 'numberofadmins' => $wgContLang->formatNum( SiteStats::admins ),
 * to
 * 'numberofadmins' => $wgContLang->formatNum( SiteStats::numberingroup('sysop') ),

Thank you very much for your contribution!

Security warning to administrators
Hi all, short question: what is the current status on the security warning directed at site administrators? Is is still valid? thanks, --Stoettner (talk) 07:24, 21 May 2013 (UTC)
 * Hi, thanks for your question. Basicly, if the poster of this warning is right, these issues do exist. As the warning was posted here without informing me on an issue-tracker or by mail (and I do not have any time to work on these issues right now), it should be considered real, but I don't know for sure. I can't give an estimate when I will be able to look into the matter. I will try to fix at least the problem concerning unescaped sys-calls, but on the XSS-front: without concrete places to look for, these issues are here to stay, unless someone finds and reports them. A rewrite is not coming, that much is certain. One side note: Some parts which are mentioned in this security warning are here by design and cannot really be fixed. This is due to the fact that a call to latex is neccessary in order to create a pdf and it needs to be sent to the user. Some parts which are said to do configuration exposure are needed to help debugging issues, so I don't believe they can be removed without a sacrifice. Wiki2LaTeX was never intended to be used as a way to create pdf files from articles by any visitor which might want one. It is always inteded to be used only by a trustworthy group of people. --HaGe-K (talk) 19:17, 22 May 2013 (UTC)