## wiki-latex plugin

Hi,

this plugin provides a wiki macro to render images from latex source. It was inspired by the graphviz-macro.
The requirements are: latex, dvips, convert (from ImageMagick).

You can find it here: http://github.com/nisrael/redmine-wiki_latex_plugin/tree/master

Nils

### Replies (40)

#### RE: wiki-latex plugin - Added by Jerome Vanthournoutover 11 years ago

Do you have a description of your plugin (snapshot, syntax, ...)?

#### RE: wiki-latex plugin - Added by Nils Israelover 11 years ago

Here a screenshot:

The syntax is as follows:

{{latex($\sum_i c_i$)}}


But I would like to use it with more comlpex formulas, like:

{{latex($\sum_{i=1}^k c_i$)}}


or

{{latex(
$$\sum_{i=1}^k c_i$$
)}}


The problem here are the curly braces und newlines. All newlines are replaced by br or p tags before the params are passed to the macro. And since the regex to match the macro arguments in formatter.rb, Line 105 matches everything, but not the closing curly brace I have no idea how to solve this without modifying the formatter.rb.

#### RE: wiki-latex plugin - Added by Yoann Rousseauabout 11 years ago

Hi !

I have some problems with this plugin.
When I write a formula like this :

{{latex($\sum_{i=1}^k c_i$)}}


I don't obtain the desired result. The formula is simply printed without being interpreted.

The problem seems to come with curly braces. When I remove them, image of the formula is displayed.
So I can't use complex formulas.

Do you have any solution to resolve this problem ?

Thanks !

P.S. : The use syntax doesn't change the problem.

#### RE: wiki-latex plugin - Added by Nils Israelabout 11 years ago

Loot at this: http://www.redmine.org/issues/3061

or use this MACROS_RE in ./lib/redmine/wiki_formatting/textile/formatter.rb to

       MACROS_RE = /
(!)?                        # escaping
(
\{\{                        # opening tag
([\w]+)                     # macro name
($$((.(?!\}\}))*)$$)?       # optional arguments
\}\}                        # closing tag
)
/mx unless const_defined?(:MACROS_RE)


Yes, it works !

Thanks a lot !

#### RE: wiki-latex plugin - Added by Matt Ueckermannabout 11 years ago

Hello,

I foolishly added the folder as "nisrael-redmine-wiki_latex_plugin-28000b9bf5a044f3a84c3cdd3cc0d562513a98db" instead of just "wiki_latex_plugin" and I got an error, that the exact plugin name (wiki_latex_plugin) should be used. I subsequently changed the folder name, and re-built the db, but then got an error the "wiki_latexes" table already exists. I no longer get an error for the plugin name usage in redmine, but I also do not get the rendered latex formula, I just get $\sum_i c_i$.

Foolish because I didn't back up my db before proceeding. Any suggestions?

Thanks!
~Matt

#### RE: wiki-latex plugin - Added by Matt Ueckermannabout 11 years ago

Also I'm running on Windows... unfortunately.

Matt Ueckermann wrote:

Hello,

I foolishly added the folder as "nisrael-redmine-wiki_latex_plugin-28000b9bf5a044f3a84c3cdd3cc0d562513a98db" instead of just "wiki_latex_plugin" and I got an error, that the exact plugin name (wiki_latex_plugin) should be used. I subsequently changed the folder name, and re-built the db, but then got an error the "wiki_latexes" table already exists. I no longer get an error for the plugin name usage in redmine, but I also do not get the rendered latex formula, I just get $sum_i c_i$.

Foolish because I didn't back up my db before proceeding. Any suggestions?

Thanks!
~Matt

#### RE: wiki-latex plugin - Added by Matt Ueckermannabout 11 years ago

Sorry, now I'm suspecting Windows to be the culprit. I use TeXnicCenter with MikTeX, and I have ImageMagick installed, but I'm not sure your plugin knows where to look for these in Windows. Anyway, that's a suspicion, I have no idea really. It would be nice to get it working, so any suggestions are very much appreciated.

Thanks! (Sorry for spamming the board. Every time after I post, I get new ideas).

#### RE: wiki-latex plugin - Added by Matt Ueckermannabout 11 years ago

Sorry, now I'm suspecting Windows to be the culprit. I use TeXnicCenter with MikTeX, and I have ImageMagick installed, but I'm not sure your plugin knows where to look for these in Windows. Anyway, that's a suspicion, I have no idea really. It would be nice to get it working, so any suggestions are very much appreciated.

Thanks! (Sorry for spamming the board. Every time after I post, I get new ideas).

#### RE: wiki-latex plugin - Added by Yoann Rousseauabout 11 years ago

Hi !

I don't really know the Windows environment, but on Linux this plugin needs 2 commands to run correctly. The first one is latex, the second one is dvipng.
If you look quickly the code of the plugin, you can see these two lines :

/app/controllers/wiki_latex_controller.rb, line 45 :

fork_exec(dir, "usr/bin/latex --interaction=nonstopmode "+@name+".tex 2> /dev/null > /dev/null")

/app/controllers/wiki_latex_controller.rb, line 46 :

fork_exec(dir, "/usr/bin/dvipng "+@name+".dvi -o "+@name+".png")

I don't know if this plugin can run on Windows, but you can try to check the two previous path in order to indicate to the plugin where to look for.

Matt Ueckermann wrote:

Sorry, now I'm suspecting Windows to be the culprit. I use TeXnicCenter with MikTeX, and I have ImageMagick installed, but I'm not sure your plugin knows where to look for these in Windows. Anyway, that's a suspicion, I have no idea really. It would be nice to get it working, so any suggestions are very much appreciated.

Thanks! (Sorry for spamming the board. Every time after I post, I get new ideas).

#### RE: wiki-latex plugin - Added by Matt Ueckermannabout 11 years ago

Thanks for pointing to the controller file... gives me something to play with.

Thus far I have tried:

fork_exec(dir, "C:\Progra~1\MiKTeX~1.7\miktex\bin\latex --src --interaction=nonstopmode "+@name+".tex")

and

fork_exec(dir, "C:\Progra~1\MiKTeX~1.7\miktex\bin\dvipng "+@name+".dvi -o "+@name+".png")

but no luck. I have two guesses, either I am suffering from my original folder problem, or Windows does not like the "+@name+" syntax. I tried replacing "+@name+" with a test .tex file and running the commands from the command window in Windows, and I ended up with a nice .png image of my test file.

Is there any way to make the temporary directory stick around so I can look at it? Perhaps figure out where in the chain things fail? I have not written any Redmine scripts, nor do I have to time right now to delve into the details, so any help would be appreciated. The problem might be that the controller file is no longer executed... the temporary directory never shows up when I check, so either it is removed each time, or it never gets created.

Thanks!

#### RE: wiki-latex plugin - Added by Matt Ueckermannabout 11 years ago

I just fixed my folder naming issue... I changed a line in:
app\views\wiki_latex\macro_inline.html.erb

from

<%= stylesheet_link_tag "wiki_latex.css", :plugin => "wiki_latex_plugin", :media => :all %>

to (the rather ugly)

<%= stylesheet_link_tag "wiki_latex.css", :plugin => "nisrael-redmine-wiki_latex_plugin-28000b9bf5a044f3a84c3cdd3cc0d562513a98db", :media => :all %>

And I no longer get the error. Still, no nice latex formulas though, I just get $\sum$ displayed for instance. Strange, at some point the temporary directory was created, but now no longer... the mystery continues.

#### RE: wiki-latex plugin - Added by Yoann Rousseauabout 11 years ago

Your problem could be caused by the used LaTeX packages. If your look for in the controller, you can see the following lines :

temp_latex.puts('\usepackage{amsmath}')
temp_latex.puts('\usepackage{amsfonts}')
temp_latex.puts('\usepackage{amssymb}')
temp_latex.puts('\usepackage[active,displaymath,textmath,graphics]{preview}')


If you don't have installed these packages, it is normal that a problem occures. So check your LaTeX installation for each of these packages.
Think to have a look in the logs of latex, the package(s) in question should be referred.
For that, don't forget to put the following line into comment because as you say that, temporary files are deleted for each execution :

File.unlink(basefilename+"."+ext)


#### RE: wiki-latex plugin - Added by Matt Ueckermannabout 11 years ago

Hello, commenting that line helped a lot, thanks Yoann!

I have all the package for latex, but! no luck yet. A few steps closer: windows doesn't like fork(), so I had to try and do without. I wrote a small batch script, latex.bat containing the following:

C:\Progra~1\MiKTeX~1.7\miktex\bin\latex --src --interaction=nonstopmode %1.tex  C:\Progra~1\MiKTeX~1.7\miktex\bin\dvipng %1.dvi -o %1.png

I've also modified the controller.rb file, and it now reads:

Dir.chdir(dir)    exec("latex "+@name+"")

Strange thing, running the batch file from cmd I get a nice .png image from a .tex file. However, when redmine creates the .tex file and runs it, there is no .png file. Not sure why. My only guess is that redmine doesn't wait for exec to finish its task. I've also reversed the order of the commands in latex.bat (after the .dvi was created) and then the .png images are created. However, they still do not get displayed, I get a:

The image "imagename.png" cannot be displayed because it contains errors

I should just really give this up... but at this point it's personal. Any suggestions appreciated.

#### RE: wiki-latex plugin - Added by Carlos de la Torrealmost 11 years ago

I've just installed the LaTeX plugin but I got the following error trying to use it:

I wrote

{{latex($\sum_i c_i$)}}

in a Wiki, and I get the following error (in a red box):

Error executing the latex macro (Mysql::Error: #42S02Table 'redmine_private.wiki_latexes' doesn't exist: SHOW FIELDS FROM wiki_latexes)


#### RE: wiki-latex plugin - Added by Matt Ralmost 11 years ago

Hello, first of all the plugin is really cool!

I passed all the steps in order to set it up and it works fine. With one exception:

Whenever I put a comma inside the latex formula, it disapears in the output image. It doesn't even get parsed. Probably it gets devoured somewhere in the regexp guts, but not sure. How can I fix it?

#### RE: wiki-latex plugin - Added by Nils Israelalmost 11 years ago

Hi,

very quick hack:

Replace in ./lib/redmine/wiki_formatting/textile/formatter.rb (in def inline_macros(text))

  args = ($5 || '').split(',').each(&:strip)  with  if macro == 'latex' args =$5
else

#### RE: wiki-latex plugin - Added by João Lopesover 10 years ago

I'm using wiki-latex plugin in redmine 0.9.3 and I'm experiencing the following dicultulty.
I made the change in order to support the & in latex as described bellow.
Puting the code:

{{latex(
\large
\begin{align*}
\frac{\partial \varepsilon}{\partial t} {+} \overline{U}_\alpha \frac{\partial \varepsilon }{\partial x_\alpha} =
& {-}2\nu \left(
\overline{ \frac{\partial u_i}{\partial x_\gamma} \frac{\partial u_i}{\partial x_\alpha } }
\frac{\partial \overline{U}_\alpha}{\partial x_\gamma} {+}\overline{ \frac{\partial u_i}{\partial x_\gamma} \frac{\partial u_\alpha}{\partial x_\gamma } }
\frac{\partial \overline{U}_i}{\partial x_\alpha} {+} \overline{u_\alpha \frac{\partial u_i}{\partial x_\gamma} } \frac{\partial^2 \overline{U}_i}{\partial x_\gamma \partial x_\alpha}
\right) \\
& {-} 2 \nu \overline{\frac{\partial u_i}{\partial x_\gamma} \frac{\partial u_i}{\partial x_\alpha} \frac{\partial u_\alpha}{x_\gamma} } {-} \nu \frac{\partial}{\partial x_\alpha} \overline{u_\alpha \frac{\partial u_i}{\partial x_\gamma } \frac{\partial u_i}{\partial x_\gamma } }\\
& {-} 2 \nu \frac{ \partial}{\partial x_i} \overline{\frac{\partial u_i }{\partial x_\gamma} \frac{\partial p}{ \partial x_\gamma} } \\
& {-} 2\nu \overline{ \frac{\partial u_i}{\partial u_\gamma} \frac{\partial^2 \tau^{sub}_{i\alpha} }{\partial x_\alpha \partial x_\gamma} }\\
& {+} \nu^2 \frac{\partial^2 \varepsilon}{\partial x_\alpha \partial x_\alpha}\\
& 2 \nu
\end{align*}
)}}

I have an error whem I save. If I remove the last \nu everything goes Ok.
I also had several problems when using the signs + and - but replacing by {+} and {-} the latex is correctly generated.

#### RE: wiki-latex plugin - Added by João Lopesover 10 years ago

Related with the problem posted yesterday,
The display of the document generates:

Parameters: {"action"=>"show", "id"=>"14", "controller"=>"documents"}Rendering template within layouts/baseRendering documents/show

ActionView::TemplateError (Stack overflow in regexp matcher: /
(!)? # escaping
(
\{\{ # opening tag
([\w]+) # macro name
($$((.(?!\}\}))*)$$)? # optional arguments
\}\} # closing tag
)
/mx) on line #11 of app/views/documents/show.rhtml:
8: <p><em><%=h @document.category.name ><br />
9: <
= format_date @document.created_on ></em></p>
10: <div class="wiki">
11: <
= textilizable @document.description, :attachments => @document.attachments %>
12: </div>

in the production.log

#### RE: wiki-latex plugin - Added by João Lopesover 10 years ago

I Solve solve the problem related in the last two posts changing the

redmine/lib/redmine/wiki_formatting/textile/formatter.rb

to

        MACROS_RE = /
(!)?                        # escaping
(
\{\{                        # opening tag
([\w]+)                     # macro name
($$(.*?)$$)?             # optional arguments
\}\}                        # closing tag
)
/xm unless const_defined?(:MACROS_RE)


Instead of the solution posted here!

1 2 (1-25/40)