diff --git a/README.markdown b/README.markdown index 6ecbe4d..6cc5725 100644 --- a/README.markdown +++ b/README.markdown @@ -54,14 +54,26 @@ Installation / Do not use commas in macro because it would be splited in different arguments and therefore plugin will not work. - -7. To allow passing attachments names as macros arguments Redmine core should be patched accordingly: here's [the patch for Redmine 1.0.2](http://www.ndl.kiev.ua/downloads/redmine-1.0.2-attachments.patch) and here is [the patch for Redmine 0.9.x](http://www.ndl.kiev.ua/downloads/redmine-attachments-in-macros.patch.gz). + To solve this comma issue and make also tikz/pgf possible you need to change the line under parse_macros in application_helper.rb + which looks +
      
+      #args = ($5 || '').split(',').each(&:strip)  # original
+      args = [($5 || '').strip]                    # replaced by
+      
Specific filters installation instructions are below. Prefedined Macros ================= +tikz +---- + +Tikz/PGF is based on description in http://www.hostedredmine.com/projects/alxa/wiki/PGF_TIKZ_Redmine and latextool.sh is taken from there. +The actual latextool.sh which has been tested here is under plugins/wiki_external_filter/lib/latextool.sh + +This part is unstable at the moment due to a lot of possiblities in tikz there only some pictures possible. You might need to adjust latextool.sh for loading libraries for specific tikz picture. + plantuml -------- @@ -99,14 +111,14 @@ Rendered output: ![PlantUML output](http://www.ndl.kiev.ua/downloads/wiki_plantuml_sample.png) -graphviz --------- +dot or neato +------------ [Graphviz](http://www.graphviz.org/) is a tool for graph-like structures visualization. It's assumed that it can be called as /usr/bin/dot. Result is rendered as SVG image or PNG fallback if SVG is not supported by your browser. -Example of usage: +Example of usage DOT: {{graphviz( digraph finite_state_machine { @@ -131,6 +143,11 @@ Example of usage: } )}} +Usage of neato: + {{gneato( + code like in graphviz + )}} + Rendered output: ![Graphviz output](http://www.ndl.kiev.ua/downloads/wiki_graphviz_sample.png) diff --git a/app/helpers/wiki_external_filter_helper.rb b/app/helpers/wiki_external_filter_helper.rb index f8721d0..a96d60a 100644 --- a/app/helpers/wiki_external_filter_helper.rb +++ b/app/helpers/wiki_external_filter_helper.rb @@ -127,6 +127,8 @@ module WikiExternalFilterHelper errors += e if e end + Rails.logger.debug "\n Content #{content} \n Errors #{errors} \n" + result[:content] = content result[:errors] = errors result[:source] = text diff --git a/bin/latextool.sh b/bin/latextool.sh new file mode 100755 index 0000000..6e0adc4 --- /dev/null +++ b/bin/latextool.sh @@ -0,0 +1,179 @@ +#!/bin/bash +# a wrapper for redmine's wiki external filter +# + +# Issues/Bugs +# - there must be only one space between 'remember picture' +# otherwise pdflatex won't be called twice + +# +# -- START command setup -- +# +cmd_pdflatex="pdflatex --interaction=nonstopmode" +cmd_latex="latex --interaction=nonstopmode" +cmd_pdf2svg="pdf2svg" +cmd_dvipng="dvipng" +# -- END command setup -- +# ------------------------------------------------------------------------------ +# show usage +# ------------------------------------------------------------------------------ +show_usage(){ +cat< output [-d| -e |-t] + -d turn debug on, i.e. it won't clean up tmp dir on exit + -e assume latex excerpt (outputs png) + -t assume tikz picture (outputs svg) +EOF + exit 1 +} +# ------------------------------------------------------------------------------ +# handle error/exit +# ------------------------------------------------------------------------------ + +catch_exit(){ + test $? != 0 && echo "
input document:
" >&2;cat $f_tex>&2;echo "
" >&2;cat $f_log >&2; echo "
" >&2 + # clean up + test $DEBUG || rm -f $d_tmp/input* $d_tmp/out*svg $d_tmp/*log + test $DEBUG || rmdir $d_tmp &>> /dev/null +} + +# ------------------------------------------------------------------------------ +# init vars +# ------------------------------------------------------------------------------ +init(){ + set -o errexit + trap "catch_exit" INT TERM EXIT + + d_tmp=/tmp/latex_sh_$$_$RANDOM + f_tex=$d_tmp/input.tex + f_log=$d_tmp/latex_sh.log + test -d $d_tmp || mkdir $d_tmp + touch $f_log + sed 's/![\ ]*}/}/' - | sed 's/{!/{/g' > $f_tex # strip some chars from redmine wiki + if [ !`grep 'remember picture' $f_tex &>>$f_log` ];then + RP=1 + fi + cd $d_tmp +} + +# ------------------------------------------------------------------------------ +# assumes latex excerpt as input +# output: png +# ------------------------------------------------------------------------------ + +do_le(){ + f_le=$d_tmp/input_le.tex + f_dvi=$d_tmp/input_le.dvi + f_png=$d_tmp/input_le1.png + echo -n " +\documentclass[12pt]{article} +\usepackage{amsmath} +\usepackage{amsfonts} +\usepackage{amssymb} +\usepackage{color} +\usepackage[active,displaymath,textmath,graphics]{preview} +\\thispagestyle{empty} +\\begin{document} +" > $f_le +cat $f_tex >> $f_le +echo -n " +\\end{document} +" >> $f_le +f_tex=$f_le +$cmd_latex $f_le &>> $f_log +$cmd_dvipng $f_dvi &>> $f_log +cat $f_png +exit 0 +} + +# ------------------------------------------------------------------------------ +# assumes tikz picture as input +# ------------------------------------------------------------------------------ +do_tikz(){ + f_tikz=$d_tmp/input_tikz.tex + f_pdf=$d_tmp/input_tikz.pdf + f_svg=$d_tmp/output_tikz.svg + + # defaults + # TODO: is it possible to do it automatically like dvipng? + scale=1 + width=100mm + height=20mm + + # parsing dimensions + dim=`head -1 $f_tex `;IFS=' '; + #echo $dim + # TODO check errors + if [ "$dim" != "" ]; then + set -- $dim; + test "$1" && width=$1 height=$2; scale=$3 + fi + echo -n " +\documentclass{article} +\usepackage{tikz} +\usepackage{geometry} +%\usepackage{amsmath,amssymb} +%\usepackage{bodegraph} +%\usepackage[symbols]{circuitikz} +%\usetikzlibrary{intersections} +\usetikzlibrary{calc} +\usetikzlibrary{positioning} +\usetikzlibrary{mindmap,trees} +%\geometry{ +% paperwidth=$width, paperheight=$height +%} +\\thispagestyle{empty} +\\begin{document} +%\\begin{tikzpicture}[remember picture, overlay,scale=$scale, transform shape] +%\\begin{tikzpicture} +%" > $f_tikz +cat $f_tex >> $f_tikz +echo -n " +%\\end{tikzpicture} +\\end{document} +" >> $f_tikz + f_tex=$f_tikz + $cmd_pdflatex $f_tikz &>> $f_log + test $RP && $cmd_pdflatex $f_tikz &>> $f_log # calling twice in case of remember picture + $cmd_pdf2svg $f_pdf $f_svg &>> $f_log + cat $f_svg + exit 0 +} +# ------------------------------------------------------------------------------ +# assumes full latex input +# ------------------------------------------------------------------------------ +do_full(){ + f_tex=$d_tmp/input.tex + f_pdf=$d_tmp/input.pdf + f_svg=$d_tmp/output.svg + $cmd_pdflatex $f_tex &>> $f_log + test $RP && $cmd_pdflatex $f_tex &>> $f_log # calling twice in case of remember picture + $cmd_pdf2svg $f_pdf $f_svg &>> $f_log + cat $f_svg + exit 0 +} +# +# Main +# +test -t 0 && show_usage +# parse args +while getopts ":det" opt; do + case $opt in + e) + LE=1 + ;; + d) + DEBUG=1 + ;; + t) + TIKZ=1 + ;; + esac +done + +#DEBUG=1 +init +test $LE && do_le +test $TIKZ && do_tikz +do_full diff --git a/config/wiki_external_filter.yml b/config/wiki_external_filter.yml index e938a91..c5061d7 100644 --- a/config/wiki_external_filter.yml +++ b/config/wiki_external_filter.yml @@ -7,14 +7,42 @@ development: &development content_type: "image/png" prolog: "@startuml" epilog: "@enduml" + tikz: + description: "Converts latex/tikz picture to svg. It requires pdflatex and pdf2svg." + template: image + replace_attachments: true + outputs: + - command: "/usr/bin/latextool.sh -t" + content_type: "image/svg+xml" + le: + description: "Converts latex excerpts to png. It requires latex and divpng." + template: image + replace_attachments: true + outputs: + - command: "/usr/bin/latextool.sh -e" + content_type: "image/png" + + latex: + description: "Converts latex to svg. It requires pdflatex and pdf2svg." + template: image + replace_attachments: true + outputs: + - command: "/usr/bin/latextool.sh" + content_type: "image/svg+xml" graphviz: description: "Constructs graph image from its textual description in DOT language, see http://www.graphviz.org" - template: svg + template: image outputs: - command: "/usr/bin/dot -Tsvg" content_type: "image/svg+xml" - - command: "/usr/bin/dot -Tpng" - content_type: "image/png" + # - command: "/usr/bin/dot -Tpng" + # content_type: "image/png" + gneato: + description: "Constructs graph image from its textual description in NEATO language, see http://www.graphviz.org" + template: image + outputs: + - command: "/usr/bin/neato -Tsvg" + content_type: "image/svg+xml" ritex: description: "Converts WebTeX expression to MathML, see http://ritex.rubyforge.org/" template: svg