Project

General

Profile

wiki-latex plugin

Added by Nils Israel over 15 years ago

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 (41)

RE: wiki-latex plugin - Added by Jerome Vanthournout over 15 years ago

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

RE: wiki-latex plugin - Added by Nils Israel over 15 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(
\begin{equation}
  \sum_{i=1}^k c_i
\end{equation}
)}}

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 Rousseau over 15 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 \begin{equation} syntax doesn't change the problem.

RE: wiki-latex plugin - Added by Nils Israel over 15 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)

RE: wiki-latex plugin - Added by Yoann Rousseau over 15 years ago

Yes, it works !

Thanks a lot !

RE: wiki-latex plugin - Added by Matt Ueckermann about 15 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 Ueckermann about 15 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 Ueckermann about 15 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 Ueckermann about 15 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 Rousseau about 15 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.

I hope it could help you.

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 Ueckermann about 15 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 Ueckermann about 15 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 Rousseau about 15 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 Ueckermann about 15 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 Torre about 15 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 R about 15 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?

Thanks in advance!

RE: wiki-latex plugin - Added by Nils Israel about 15 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
    args = ($5 || '').split(',').each(&:strip)
  end

RE: wiki-latex plugin - Added by Matt R about 15 years ago

Thanks! It works like a charm now!

RE: wiki-latex plugin - Added by Steve G over 14 years ago

Hi,

Thanks for your great plugin!

Just a few remarks:
  • in 'vendor/plugins/wiki_latex_plugin/app/controllers/wiki_latex_controller.rb': latex and dvipng paths must be fixed if they are not '/usr/bin'
  • the '&' character can't be used yet in LaTeX formulas. It is transcribed to ' x % x % ' (without the spaces), which seems to be equivalent to '&' in both sides (specific to Redmine or inherent to Ruby?)

Any ideas to manage the '&' issue?

RE: wiki-latex plugin - Added by Steve G over 14 years ago

Steve G wrote:

Hi,

Thanks for your great plugin!

Just a few remarks:
  • in 'vendor/plugins/wiki_latex_plugin/app/controllers/wiki_latex_controller.rb': latex and dvipng paths must be fixed if they are not '/usr/bin'
  • the '&' character can't be used yet in LaTeX formulas. It is transcribed to ' x % x % ' (without the spaces), which seems to be equivalent to '&' in both sides (specific to Redmine or inherent to Ruby?)

Any ideas to manage the '&' issue?

A quick and dirty fix could be to replace ' x % x % ' by '&' in wiki_latex_controller.rb:

40: temp_latex.puts @latex.source.gsub("x%_remove_x%","&")

where the '_remove_' must be deleted (added in the comment to prevent ' x % x % ' to be converted to '&')

Then {{latex($\begin{pmatrix}1&0\\ 0&1\end{pmatrix}$)}} leads to a nice

RE: wiki-latex plugin - Added by Thimios Dimopulos over 14 years ago

thank you very much for the great plugin.

I just installed it on Redmine 0.9.1.stable.3369 and did the basic test with {{latex($\sum_i c_i$)}} but it does not seem to work, i just get $\sum_i c_i$ on the wiki page.

Has anyone tried to install the plugin on Redmine 0.9.1.stable.3369?

The plugin code on github is one year old.

Are there any plans for reviving it?

thanks again.

RE: wiki-latex plugin - Added by Paul H over 14 years ago

I have it working on redmine 0.9.3 :)

The 'File.unlink' hint was key for me getting it working - I didn't have all the latex packages going.

Note that if you see $\sum_i c_i$ as described in previous post, try right-clicking it. You'll find its an image, and the text is the image's alt tag. In my case, latex wasn't able to generate the image, so only the alt tag was shown.

RE: wiki-latex plugin - Added by João Lopes over 14 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 Lopes over 14 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/base
Rendering 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 Lopes over 14 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-25/41)