DFG's picture

D r u T e X

1. Installation
2. Configuration
3. Usage
4. Additional modules
5. Developer notes
6. Author

1. Installation

1) Download the DruTeX module from the Drupal website and unpack it to the modules directory. You now have a directory modules/drutex.

2) Go to the module admin section and enable "drutex".

3) Go to the input-filters admin section and create a new input format. You can choose an arbitrary name, but "DruTeX" would make sense. When you create a new format, you can select an input filter from a list: Just choose DruTeX.

4) Go again to the input-filters admin section, and select "configure" for the newly added input format. Click on the "configure" tab, and you are able to adjust many settings of DruTeX.

5) Go and test DruTeX: Create a new node, select your new input format, and try to render something, e.g. just try $x^2$.

2. Configuration

All configuration is done on the input filter settings page.


You can activate the following facilities of DruTeX:
* LaTeX to HTML: Converts many LaTeX commands and environments to plain HTML.
* LaTeX Renderer: Provides different environments to create rendered images (especially maths). For most of the users, this is the most important feature.
* Line break converter: Converts line breaks into HTML (i.e. <br> and <p> tags).
* PDF Generator: Allows to generate pdf-versions of a node (with decent html2latex features).

Further submodules are available and can be made ready for activation by copying the submodule files from modules/drutex/contrib to modules/drutex. For more, see chapter 4.

Base Settings

In the base settings you can set the paths for temporary dir, the image directory and the image url.

LaTeX Renderer

Here you can adjust the LaTeX template, DPI (Resolution) and conversion command used for the LaTeX-to-Image conversion. If you know LaTeX well, you may want to create your own template. The templates reside in modules/drutex/templates/render and are not difficult to understand (if you know LaTeX well).

Line break converter

LaTeX treates a single new line not as a new line, but only as space - while Drupal would interpret it as a real newline. Two or more new lines, that means a least one empty line, are treated as new paragraph by both, Drupal and LaTeX. So the only critical point are single new lines.

You can choose between Drupal- and LaTeX-interpretation of new lines. You could also completely deactivate this submodule.

PDF Generator

Here you can also adjust the LaTeX template and the conversion command used for the generation of the pdf files. The templates reside in modules/drutex/templates/pdf - you may want to edit this if you know LaTeX well.

Security restrictions

If you activate this, you can define a list of LaTeX commands and environments that are allowed to get executed. Then, all other commands and environments would cause DruTeX to stop processing the potentially dangerous code.

3. Usage

Rendering LaTeX / Math

Writing maths works as in LaTeX. Use dollar signs to enclose inline math, e.g. $x^2$. Examples for paragraph math are [ x^2 ] and $$x^2$$ (both variants are equivalent). There is also a display-style inline math environment, compare $\sum_{k=1}^\infty \frac{1}{k}$ and $!\sum_{k=1}^\infty \frac{1}{k}$.

To make a dollar sign, you have to type \$ as in LaTeX!

Arbitrary LaTeX code can be rendered as in this example: <tex>Let $x^2$ be a natural number.</tex>

There are also more elaborate environments to write math - they support auto-numbering, referencing and more. These environments are <equation> and <equations>. They both support the same attributes.

E.g. rendering an equation with a different resolution: <equation dpi="200">e^{i \cdot \pi} = -1.</equation>

To give the equation automatically a number, you have to give it an id: <equation id="euler">e^{i \cdot \pi} = -1.</equation>

You now can produce a link to that equation by typing \ref{euler}, or even better (\ref{euler}).

You can also give it a name instead of a number: <equation id="euler" name="Euler's Identity">e^{i \cdot \pi} = -1.</equation>

An example for the <equations> environment is given by:
\int \ln(x) \;dx
&= \int 1 \cdot \ln(x) \;dx \
&= x \cdot \ln(x) - \int x \cdot \frac{1}{x} \;dx \
&= x \cdot \ln(x) - x

The spaces on the left are optional.

PDF Generator

The pdf version of a node can be retrieved by accessing drutex/pdf/nid where nid is the node id. But only users with the "access pdf files" flag can access this link! You can configure this on the access controal page admin/access. There is also the possibility to get the LaTeX source by accessing drutex/tex/nid.


To prohibit some text from being processed by DruTeX, you can use <code> and <notex>, e.g. <notex>$x^2$</notex>.

4. Additional modules

Copy the submodule from modules/drutex/contrib to modules/drutex. Submodules availabe:
* MathML support through blahtex (in development). See also
* Eukleides support, for geometric figures (in development). See also
* Example module for developers.

5. Developer notes

DruTeX has an own submodule system, alldefined in drutex.module. modules/drutex/contrib/ will explain how to write a submodule. There is also a Drupal-wide hook drutex2html, which returns entities as in subhook_node2html, see

To test if a submodule is marked active in a given input format, use drutex_submodule_is_active(), e.g. drutex_submodule_is_active('security', $format).

6. Author


Installation requirements

yoka's picture

My first thought was: how do they render that code? Do they ship a tex distribution or even code their own distri?

Not until I read my error.log I found out that the template calls latex via shell invocation. Installing a propper latex distribution should really be the first issue on the how-to!

Besides: How do I run my own latex compiler with system limited access (common web hoster)? Is'nt this the major setting for drupal?

Installing a propper latex

Steven Jones's picture

Installing a propper latex distribution should really be the first issue on the how-to!

Yes, probably.

How do I run my own latex compiler with system limited access (common web hoster)?

If they don't have LaTeX installed you can use the remote rendering option, and get all the images rendered on a remote server that does have LaTeX installed, or you can use the mimetex feature if you have cgi permissions.

I have been looking for how

jpcurley25's picture

I have been looking for how to get a proper latex distribution to work with Drutex on Drupal 7. I've been looking everywhere to no avail. Does Drutex even work with D7?

Right now, when I try to enable Drutex, I am just shown a blank screen as if the installation crashed. I have LaTeX working on my mediawiki installation on the same server (mediawiki will be replaced by drupal entirely) so I know LaTeX does work on the machine.

However, since someone else set that up I am not opposed to a fresh LaTeX install so I know how it all works.

Is Drutex 6.x compatible

esatel's picture

Hi. I was wondering if Drutex is being maintained for 6.x? A lot of my interest in experimenting with Drupal had to do with this module. Thanks.

Not Yet

Steven Jones's picture

No D6 port, yet, but one is planned for the summer, along with a major upgrade.

If you have ANY feedback, would be the place to put it!

What about Windows?

stokito's picture

DruTex can be runed only on Linux/UNIX platforms?

Remote Latex

hsrai's picture

I could not find our way to enable remote use of Latex. May I request to help me on setting up use of remotely installed LaTexand dvipng

PDF of a node

hsrai's picture

I used Drupal 5 with DruTex. Math rendered fine. Please see:

However, I could not understand use of drutex/pdf/nid where nid is the node id.

I enabled "access pdf files" flag to all users.

If I use:

I get link:

with warnings, which are reproduced below signature.

How I can get pdf of a node?


////// response //////////////////

Page not found

* warning: Invalid argument supplied for foreach() in

/home/hsrai/public_html/drupal/drupal-5.10/modules/node/node.module on
line 561.
* warning: implode() [function.implode]: Bad arguments. in
/home/hsrai/public_html/drupal/drupal-5.10/modules/node/node.module on
line 565.
* user warning: You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near '' at line 1 query: SELECT n.nid, n.vid, n.type,
n.status, n.created, n.changed, n.comment, n.promote, n.sticky,
r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log,
r.format, u.uid,, u.picture, FROM dr1_node n INNER JOIN
dr1_users u ON u.uid = n.uid INNER JOIN dr1_node_revisions r ON r.vid
= n.vid WHERE in
on line 172.
* warning: Invalid argument supplied for foreach() in
/home/hsrai/public_html/drupal/drupal-5.10/modules/node/node.module on
line 561.
* warning: implode() [function.implode]: Bad arguments. in
/home/hsrai/public_html/drupal/drupal-5.10/modules/node/node.module on
line 565.

Installation Problem

elf_cash's picture

Is there a forum available for this module? I'm not sure this is the best place to post this(new to drupal) but I'm getting the following output from the Drutex::Toolbox configuration. Any ideas on what's causing the two failures?


The temporary directory is writable.
The image directory is writable.
Executing "latex" failed. Either LaTeX isn't installed or the "latex" executable is not in one of the search paths.
You cannot render high-quality images without LaTeX.
Mimetex maybe an alternative for you. Consult the documentation on how to use Mimetex.
Executing "dvipng" failed. Either dvipng isn't installed or the "dvipng" executable is not in one of the search paths.
You cannot use dvipng for rendering images (check the conversion method above).
Executing "convert" (ImageMagick) was successful: Version: ImageMagick 6.0.7 07/25/08 Q16


Fixing installation problem

physcied's picture

I had the same problem. This was because "latex" and "dvipng" were not in the same directory as "convert" which was executed successfully. So I made symbolic links of "latex", "dvipng" and "pdflatex" and put them in the same directory as "convert (/usr/bin/ in my case).

I hope this helps.

fixing latex path

abogom's picture

Another solution is this.

exec() function is used twice in The first parameters are 'latex' and 'dvipng'. To make this work, you can replace thses with the full path to your latex installation.

Alexander Bogomolny

Alexander Bogomolny

config in Windows (images not embedding)'s picture

I'm trying to get DruTeX 6.x-1.0-beta1 to work with Drupal 6.10 on a Windows XP localhost running Apache server and MySQL. Images are not being embedded for the math symbols. For example, a post whose entire body is

<tex>Let $x^2$ be a natural number.</tex>

when published, generates a .tex file in a subdirectory of htdocs\drupal\tmp\, but in the published post I see
TeX Embedding failed! in place of what should be the rendered math.

DruTeX is installed in E:\Documents\htdocs\drupal\sites\all\modules and enabled. Among the DruTeX settings are:

  • Temporary directory: E:\Documents\htdocs\drupal\tmp
  • Template: default.tex
  • Conversion method: Custom
  • Conversion method (Custom):
    cd [TMP_DIR]; TEXINPUTS="[DRUTEX_DIR]//:" D:\WP\MiKTeX 2.7\miktex\bin\latex -interaction=batchmode [HASH].tex
    D:\WP\MiKTeX 2.7\miktex\bin\dvipng -o [IMG_FILE] -D [DPI] -T tight [TMP_DIR]/[HASH].dvi

Am I using a correct syntax for the paths to the latex and dvipng executables, with Windows-type backslashes? Or do I need to use, instead, *nix-style forward slashes?

I did try putting the entire path to each executable within double-quotes, in case the embedded space character in the path was causing trouble, but that didn't seem to make any difference.

What other settings for DruTeX might be causing the trouble—and what do I do to find out?

The template being used, in htdocs\drupal\sites\all\modules\drutex\templates\render, is:

% good math support
% UTF-8 support
% other packages

Your problem could be that

jrviorato's picture

Your problem could be that you forgot to configure the filter section, that is, Administer » Site configuration » Input formats >> [your default filter]. On the configure tab menu you should see the Drutex::Latex Render section, where you must select dvipng windows as Conversion Method.

Hope these help.

jrviorato's picture

I went through a lot of pain to figure out how to make Remote Latex work. But, I finally make it.

I Installed Drutex on a remote server (Godaddy) with Drupal. But I don't have root access neither Latex installed on my remote server. Then, i decided to activate Drutex remote latex rendering, to create images on my home made server (Windows XP, Apache 2 and PHP 5) and send them to my remote server.

Well, I install Drutex 6.x-1.0-beta1 on both servers. And I did the next to make the connection work:

  • On the server that is going to display the images (In my case, the Godaddy server):
    • Go to your default filter configuration tab (admin/settings/filters/[Your_filter_id]/configure)
    • Check the "Remote LaTeX Renderer" check box.
    • Uncheck the "Latex Render" check box (I don't know if this is really necessary)
    • Go to the "DruTeX :: Remote LaTeX Renderer" section.
    • Write the remote server path, it should be "http://[path to drupal home]/drutex/remote" (NOTE: Not drutex/render as the "Remote server Path" comment said).
  • On the server that is going to create the images (In my case, it was my local server with Windows):
    1. Some Drutex configuration.

      • Go to the "drutex settings" page.
      • Check the "Allow remote LaTeX rendering on THIS server" check box.
      • On the "Allowed remote IPs" text area, I wrote the IP of the server who is going to display the images.
      • Choose temp folder and template (This is not so important, the defaults values are ok).
      • For Conversion Method I chose "Custom", because the "dvipng" method doesn't seem to work on Windows.
      • On the "Conversion Method (Custom)" text area i wrote:
        cd [TMP_DIR] & latex -interaction=batchmode [HASH].tex
        dvipng -o [IMG_FILE] -D [DPI] -T tight [TMP_DIR]/[HASH].dvi

        (Note: this is the "dvipng Windows" conversion method that i found on the sources files).
    2. A Drutex Patch.

      • Open the file "".
      • On the line 257 I add:
               foreach($ip_allow as $allow){
                  $ip_allow[$i] = trim($allow);

        (NOTE: It seems that this change is necessary)
      • I Change the line 289:
        return ip_server();
        for the line:
        return $_SERVER['REMOTE_ADDR'].'';    
        (NOTE: this change has already been made on the most recent CSV version).
      • On the line 292 (Just after the line code $ip = ip();), I added:
        $ip = trim($ip);

Well, after all these, all works perfect now.

Security Consideration

Justin_KleinKeane_unused_see_user28474's picture

The installation instructions read:

3) Go to the input-filters admin section and create a new input format. You can choose an arbitrary name, but "DruTeX" would make sense. When you create a new format, you can select an input filter from a list: Just choose DruTeX.

If a site is configured in such a way (where only the DruTeX input filter is applied) anyone using the new input type can inject arbitrary HTML (cross site scripting attacks). It is important to also include regular HTML filtering to avoid this danger. Selecting only the DruTeX filter creates a dangerous content type.

Waiting for localhost: page doesn't display

lucacerone's picture

I'm trying to setup Drutex for Drupal 6.x on my webserver
(XAMPP 1.7 on Win Vista 32bit).
I followed the guide but when I try to create a content having
a formula: when I save I just get to wait for localhost and never see the page appear,
the same is if I try to access the newly created page (that can be painful if by default
is published on the homepage).
In the "Debug" section everything seems fine:

The temporary directory is writable.
The image directory is writable.
Executing "latex" was successful: MiKTeX-pdfTeX 2.7.3235 (1.40.9) (MiKTeX 2.7)
Executing "dvipng" was successful: This is dvipng 1.9 Copyright 2002-2006 Jan-Ake Larsson
Executing "convert" (ImageMagick) was successful:

In the xampp/temp directory, there are some directories with
a .tex file (containing the right formula),
and the log file is blank.

Any advice on how I could solve? If you need further details just ask (I'm not a programmer,
so don't know what can be helpful and what not).
Thank you very much in advance,

Drutex created only pictures, but no formula.

lakul's picture


I have followed the installation instructions exactly and the installation worked without error. But if I type $ x ^ 2 $, created Drutex just an image with $ x ^ 2 $. I am using Drupal 6 and Drutex 6.x-1.0-beta1:

The temporary directory is writable.
The image directory is writable.
Executing "latex" was successful: pdfTeX using libpoppler 3.141592-1.40.3-2.2 (Web2C 7.5.6)
Executing "dvipng" was successful: This is dvipng 1.11 Copyright 2002-2008 Jan-Ake Larsson
Executing "convert" (ImageMagick) was successful: Version: ImageMagick 6.5.1-0 2009-08-27 Q16 OpenMP

Can you help me?

Are you wrapping your

elf_cash's picture

Are you wrapping your equation in <tex> </tex> tags?


lakul's picture

Yes, but even there only the images are generated.

You may need to adjust the

elf_cash's picture

You may need to adjust the precedence of your filters(the order that drupal runs the various filters on your input). You can find this in admin-> input formats. I have drutex weighted at 10 and that ensures that it will run first. Depending on how many different input formats you have you may need to play around with the weightings to make sure everything comes out the way you expect. Also, of course, make sure that you have drutex checked as the "input type" whenever you are inputting tex for drutex to filter.

Cause of the problem

cuttrissb's picture

The images are being created properly. What the problem is is that when the DruTex referenced the image (through the Only local images are allowed. tag) the image isn't found. The major annoyance with the .png format is that it allows some supplementary text to be displayed when the image isn't found - it is this text that you're seeing. I've just written up an explanation of this here:

Hope this helps - long time coming...

two problems

aghatak's picture

Hey, I am a student of Indian Institute of Technology. I have created my department's webpage at , and want to install drutex in it.

two problems are occurring.

  1. no images are getting embedded, after saving the node with, say, $x^2$, a blank body is what i can see.

  2. at every page, this warning is coming up: "warning: Parameter 1 to drutex_pdf_nodeapi() expected to be a reference, value given in /var/www/modules/drutex/drutex.module on line 830"

can you please tell me how to get rid of these problems?

About the warning

jrviorato's picture

It seems to be a problem with PHP 5, i got the same error when a i upgrade my php server from php4 to php5. What i did? Well, i modify all the functions that sent a warning removing the instrucction '&' (that means, pass by reference) and ... problem solved!.

Hope this helps

even if I write : Let $x^2$

aghatak's picture

even if I write : Let $x^2$ be a natural number.

the output comes: Let be a natural number.

SoC 2006: DruTeX

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: