Go Back   vb.org Archive > vBulletin Modifications > vBulletin 4.x Modifications > vBulletin 4.x Add-ons
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
vLaTeX - Math parsing with LaTeX Details »»
vLaTeX - Math parsing with LaTeX
Version: 0.5.2, by Pod Pod is offline
Developer Last Online: Aug 2019 Show Printable Version Email this Page

Category: BB Code Enhancements - Version: 4.2.x Rating:
Released: 12-19-2009 Last Update: 12-15-2012 Installs: 53
Uses Plugins Auto-Templates
Re-useable Code Additional Files Translations Is in Beta Stage  
No support by the author.

vLaTeX allows your users to include mathematical equations written in LaTeX into their posts, rendered in high quality graphic files (either png or gif). Such ability is instrumental in scientific or educational oriented forums. When I started in vb two years ago, there ware a number of solutions available, but none of them suited my needs completely, so I developed my own integration between (a modified version of) Benjamin Zeiss' LatexRender and vBulletin. With the new vBulletin 4.0, I decided to improve some of the features of this product, and to release it with the hope that it turns out to be useful to any of you.


What is LaTeX?

LaTeX is a set of macros for the TeX typesetting system. It is the defacto standard of communication within the scientific and mathematical community. It works pretty much like a programing language: you write a text source file, and the latex executable compiles it in a DeVice Independent file (DVI), which can be later converted to the desired format (postscript, pdf, etc.).

This mod (thanks to a modified version of the LatexRender class) does all this work in the background. It takes the formula code, inserts it in a source file, compiles it and converts the output in a high quality image file (png or gif, depends on your settings) to show in the post.


Requirements

This mod relies on your server having available the following external programs. They are pretty standard in most Linux distributions, so hosts can install them easily (if they want to, some don't). Please, check your server meets this requirements (or ask your host to install the programs) before trying to use vLaTeX:

- latex: the LaTeX compiler. Check the TeX live distribution (http://www.tug.org/texlive/).

- dvips: converts the DVI file to PS. Usually included in all latex distributions.

- convert: as it name suggests, converts between a large number of graphic files. Belongs to the ImageMagick package. Needs ghostscript.

- identify: among other things, measures the size of image files. Also belongs to ImageMagick

- Ghostscript: PostScript and PDF language interpreter and previewer. Is called by convert in order to handle ps files.


Features

Creates a new BBcode, usually [TEX] (thought the tag name is configurable via the admin cp), which contents are processed thought LaTeX to generate image files. There are four calling modes:

- [TEX]E= mc^2[/TEX] in-line mode. The image is included in the middle of the text, without line breaks. It tries to adjust the baseline of the formula by adjusting the vertical-align CSS property; the results aren't always perfect, but it does its best.

- [TEX=null]E = m c^2[/TEX] displayed mode: The formula is displayed (usually centered) between two paragraphs.

- [TEX=*]E = m c^2[/TEX] auto-numbering mode: The formula is displayed (usually centered), and numbered.
NOTE: The auto-numbering depends on the CSS counter system, so some old browsers (most notably ie 7 and older) will show these equations untagged, like [TEX=null]. Don't blame me, blame non-standard compilant browsers.

- [TEX=tag]E = m c^2[/TEX] displayed with tag: The formula is displayed (usually centered) between two paragraphs, and tagged with the specific tag.

In the last two modes, the tags are displayed at the right (left if you use RTL) between brackets, in a (configurable) color.

The formulas are compiled by creating a small tex file and running the native LaTeX program throughout it. You can choose to wrap the formula with the standard dollar ($ ... $), the align or gather amsTeX environments. The standard dollar is recommended since the baseline hack works better with it, but the gather environment allows to create multiline equations using the \\ separator.

This mod also introduces a second BBcode, [EQREF]tag[/EQREF], which outputs (tag), with the same style of the equation tags. It's useful to let users make reference their formulas.

A double click on the image of a generated image will open a pop-up displaying the LaTeX source code used to generate the formula.

Menu with Common used LaTeX commands can be shown below the advanced mode editor. The admin can customize the commands of the menu thought the admin control panel.


Admin features

Image files are cached, so every unique formula is only processed once.

Fully configurable via Style Variables and templates. It is also fully phrased.

It doesn't change any vb default template, so upgrading should be easy.

Includes a list of blacklisted latex commands for security (configurable in the admin cp).

The admin can customize the preamble of the latex file in the admin cp. This is useful to define new commands that your community uses often, or to include packages.

Error messages can be customized in the phrase system.

Memory usage of ImageMagick commands (convert and identify) can be limited in the admin control panel.


Installation / Upgrade

1.- Unzip the mod files.

2.- Upload the vLaTeX directory to your forum root. The generated folder structure should look like this:

vLaTeX/
vLaTeX/index.htm
vLaTeX/class_vlatex.php
vLaTeX/functions_vlatex.php
vLaTeX/vlatex.js
vLaTeX/pics/
vLaTeX/pics/index.htm
vLaTeX/temp/
vLaTeX/temp/index.htm

3.- Change the permissions of the pics and temp folders so the web server can write on them.

4.- Import the product XML in your admin control panel. If you're upgrading, set "Allow Overwrite" to yes.

5.- Go to Admin CP > Settings > Options > vLaTeX - Math Parsing

6.- Make sure the path to latex, dvips, convert and identify executables is correct. Those settings default to the most common values in most linux distributions, but every host is a different world.
If you have shell access, you can check the location of the executables with the following commands:
which latex
which dvips
which convert
which identify

7.- Make sure the path to the Images and Temporal directory are correct. You can change them if you don't like the default value, but the directories must exist and the server must have permissions to write on them.
For extra safety, you could move the temp folder out of the public accessible directory three, thought it should not be needed, since files are deleted in matter of milliseconds.

8.- Set the rest of options as you wish.

9.- Test the product in some posts.

10.- If you wish to add a button in the advanced editor tool-bar for this mod, you can add it using the admin cp section Custom BB Codes (write anything you want in Replacement, this mod will overwrite it). You can use any tex icon, for instance http://www.iconfinder.com/icondetails/3780/16/tex_icon


Error messages

The LaTeX parsing can fail for a number of reasons. In such case, an error message is displayed instead of the formula. Here's a list of all possible error messages and their meaning:

- "Image too big {1}, max {2}x{3}", The resulting image is bigger than the allowed dimensions.

- "Blacklisted command", The user attempted to compile a formula with a forbidden command.

- "Can't move image", Image formula could be created, but I could not be moved to the destination folder. Check that the directory exists and has write permissions.

- "Convert failed", Formula could be compiled, but could not be converted to png/gif. Check the convert program path.

- "Compile failed", The formula could not be compiled. Check that the temporal directory has write permissions and that the latex path is correct.

- "Code too long, max. {1} characters", The formula code was too long. The maximum length can be configured in the admincp.

- "Formula not found", The compilation and convert process appeared to not raise any error, but the image was not found on the destination folder. Check for permissions in the destination folder and/or IO errors.

- "Pictures directory unwritable", The destination folder does not exist, or has no write permissions.

- "Temp. dir unwritable", The temporal folder does not exist, or has no write permissions.

- "Unknown error", Any other error condition.


Disclaimer

This mod is in beta phase, if you find bugs, please tell me how to reproduce them so I can improve it. It is distributed as is, with the hope that it is useful for someone, but without any warranty. Nor will I accept any responsibility or liability if it doesn't work as expected, or even if it breaks something.
This mod is mainly developed for personal usage. I will listen to good ideas, but I can't guaranty that I will be implemented requested features.


License

This mod is distributed under the LGPL.(http://www.gnu.org/copyleft/lesser.html). As is, you can freely distribute it or any derivative work provided that: 1) you acknowledge the work of the previous coders (like myself and Zeiss), 2) you release it under the same license (or GPL).



Acknowledgments

This mod (in particular, the class_vlatex.php file) is strongly based on the LatexRender class by Benjamin Zeiss (http://www.mayer.dial.pipex.com/tex.htm).

The baseline hack by the work of Maarten Sneep (http://mactextoolbox.sourceforge.net.../baseline.html).


Compatibility

The last version of this mod (0.5.1) requires vb4.2.0 or higher. It should work on previous CKEditor versions, but it was not tested.

If you wish to use it in a pre-CKEditor vb installation, you can use the previous vLaTeX version (0.4.1). If you want to use it in an older vb4.0.x release, you can download version 0.3 (which is compatible with vb4.0.1 or higher). Take into account that old versions of this hack have less features and might have some issues fixed in later versions.

Support will be given only for the last version of this mod.



History

2009 / 12 / 19 - First (beta) release

2009 / 12 / 20 - version 0.2
Fixed baseline problem of in-line formulas in CMS articles.
Improved error handling.
Included Spanish translation

2010 / 1 / 24 - version 0.3 (requires vb4.0.1)
Fixed extra space after in-line equations.
Won't break down if vb's CSS is stored as files.
New pop-up showing the formula source code upon double-click.

2010 / 7 / 23 - version 0.4 (requires vb4.0.4)
Improved support for CSS stored as files.
Fixed bug of js file not being loaded on certain servers.
Menu with common LaTeX commands under vb's advanced editors.
Equations will no longer be break by preview in blogs or CMS articles.

2010 / 4 / 24 - version 0.4.1 (requires vb4.0.4)
Improved compatibility of the Common Commands quick-menu with IE browser.

2012 / 12 / 07 - version 0.5.1 (requires vb4.2.0)
CKEditor support.
Memory limit for imagemagick commands.
Code pop-up now can overflow postbit boundary.

2012 / 12 / 17 - version 0.5.2 (requires vb4.2.0)
Introduced Formula Wrapper option.

Download Now

File Type: zip vlatex-0.3.zip (16.6 KB, 103 views)
File Type: zip vlatex-0.4.1.zip (21.3 KB, 261 views)
File Type: zip vlatex-0.5.2.zip (21.4 KB, 124 views)
File Type: xml vlatex-spanish-language.xml (14.0 KB, 33 views)

Screenshots

File Type: jpg screenie1.jpg (41.2 KB, 0 views)
File Type: png screenie2.png (81.0 KB, 0 views)
File Type: jpg screenie6.jpg (56.0 KB, 0 views)
File Type: png screenie3.png (74.8 KB, 0 views)
File Type: jpg screenie0.jpg (55.1 KB, 0 views)
File Type: png screenie4.png (89.7 KB, 0 views)

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.
2 благодарности(ей) от:
Daniel, dukeblue219

Comments
  #122  
Old 12-12-2012, 08:49 PM
emath emath is offline
 
Join Date: Sep 2008
Posts: 252
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

on the errors from the log file i wrote it says : "unable to open image `143ebf4431f6923c64587a2965b56602_1355335161.ps': No such file or directory."

so it seems that maybe something in the script is wrong, the directory isnt right..
Reply With Quote
  #123  
Old 12-12-2012, 09:06 PM
Pod Pod is offline
 
Join Date: Jun 2007
Posts: 129
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by emath View Post
on the errors from the log file i wrote it says : "unable to open image `143ebf4431f6923c64587a2965b56602_1355335161.ps': No such file or directory."

so it seems that maybe something in the script is wrong, the directory isnt right..
Every formula goes thought several formats: tex, dvi, ps and finally png. According to your first message, the process breaks at the dvi phase, so it's expected that the ps file doesn't get created.

To test further, please do the following. Edit vlatex/class_vlatex.php. Around line 411 (pretty at the end), change

PHP Code:
if (file_exists($f)) unlink($f); 
To

PHP Code:
// if (file_exists($f)) unlink($f); 
This effectively disables the cleanup of the temp directory. Please clean it by hand (something like rm vlatex/temp/*) so we can see the results of the test.

Then, log into your forum and try to add a formula to a post. The temp folder will fill up with some files, so we can know how many of them get created ok. Please, tell me the result of ls -l after that test, or delte also vlatex/temp/index.htm so I can take a look at the directory listing at http://www.emath.co.il/forums/vlatex/temp/ (you can recreate the file after the test)
Reply With Quote
  #124  
Old 12-12-2012, 09:26 PM
emath emath is offline
 
Join Date: Sep 2008
Posts: 252
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i commented the row u asked .

the ls -l gives now (while im in the temp dir) :

total 56
-rw-r--r-- 1 emath emath 49872 Dec 12 23:23 efa4c40fe23d50f46436522f01f442b1_1355350982.tex
Reply With Quote
  #125  
Old 12-12-2012, 09:36 PM
Pod Pod is offline
 
Join Date: Jun 2007
Posts: 129
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by emath View Post
i commented the row u asked .

the ls -l gives now (while im in the temp dir) :

total 56
-rw-r--r-- 1 emath emath 49872 Dec 12 23:23 efa4c40fe23d50f46436522f01f442b1_1355350982.tex
Now, while in the temp dir, write the following:

Code:
(Path to LaTeX)  --interaction=nonstopmode efa4c40fe23d50f46436522f01f442b1_1355350982.tex
Where Path to LaTeX is the path to latex as entered in the admincp. The default is /usr/bin/latex, so if you have the default value your line would be

Code:
/usr/bin/latex  --interaction=nonstopmode efa4c40fe23d50f46436522f01f442b1_1355350982.tex
This is the command the mod is issuing (Assuming that you didn't delete the file generated by the previous test; if you did, please create a new one).

See if any error happens, and see if more files are generated in the directory (i.e, check ls -l again).



If the previous command failed, try the same line but without the full path (just latex instead of /usr/bin). This should work, since we tested a different thing a while ago.
Reply With Quote
  #126  
Old 12-12-2012, 09:39 PM
emath emath is offline
 
Join Date: Sep 2008
Posts: 252
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ok, the command succeeded. (with the full path)

ls -l gives :

Quote:
total 320
-rw-r--r-- 1 emath emath 54659 Dec 12 23:29 218f45bd0e29f218b0dc1857255890a0_1355351345.tex
-rw-r--r-- 1 emath emath 54659 Dec 12 23:29 5d890bc62b4786e4e033f3109d6f514f_1355351364.tex
-rw-r--r-- 1 emath emath 54659 Dec 12 23:29 bef8c61085cc0b691603940a31f6e3e8_1355351327.tex
-rw-rw-r-- 1 admin admin 8 Dec 12 23:36 efa4c40fe23d50f46436522f01f442b1_1355350982.aux
-rw-rw-r-- 1 admin admin 6 Dec 12 23:36 efa4c40fe23d50f46436522f01f442b1_1355350982.depth
-rw-rw-r-- 1 admin admin 212 Dec 12 23:36 efa4c40fe23d50f46436522f01f442b1_1355350982.dvi
-rw-rw-r-- 1 admin admin 5125 Dec 12 23:36 efa4c40fe23d50f46436522f01f442b1_1355350982.log
-rw-r--r-- 1 emath emath 54659 Dec 12 23:23 efa4c40fe23d50f46436522f01f442b1_1355350982.tex
-rw-r--r-- 1 emath emath 54659 Dec 12 23:25 fd3be24dfc7f5c66c09e58c2485731a1_1355351109.tex
the only error that might be is : /usr/bin/latex: /usr/local/lib/libpng12.so.0: no version information available (required by /usr/bin/latex)
Reply With Quote
  #127  
Old 12-12-2012, 10:00 PM
Pod Pod is offline
 
Join Date: Jun 2007
Posts: 129
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by emath View Post
ok, the command succeeded.

ls -l gives :



the only error that might be is : /usr/bin/latex: /usr/local/lib/libpng12.so.0: no version information available (required by /usr/bin/latex)
That's very weird. The libpng error shouldn't matter at this point since the dvi file is generated; but it isn't when the same command is issued by the webserver.

It might be worth trying to install libpng just to see if that makes any difference; If you installed latex using a package manager (apt-get, yum, yast or whatever) then the dependence should have been installed, check your linux distribution on details why it wasn't.

Anyway, I don't think that's the problem, so let's try something else. I'm going to prepare a debug version of class_vlatex.php to gather more information and I'll get back to you when I have it.

That is unless... and I know this is a delicate question, but would you consider giving me temporary and limited ssh access to the restricted vlatex directory so I could perform tests by myself much more quickly?

I'll get back to you when I have the debug class_vlatex.php.
Reply With Quote
  #128  
Old 12-12-2012, 11:41 PM
Pod Pod is offline
 
Join Date: Jun 2007
Posts: 129
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Pod View Post
That's very weird. The libpng error shouldn't matter at this point since the dvi file is generated; but it isn't when the same command is issued by the webserver.

It might be worth trying to install libpng just to see if that makes any difference; If you installed latex using a package manager (apt-get, yum, yast or whatever) then the dependence should have been installed, check your linux distribution on details why it wasn't.

Anyway, I don't think that's the problem, so let's try something else. I'm going to prepare a debug version of class_vlatex.php to gather more information and I'll get back to you when I have it.

That is unless... and I know this is a delicate question, but would you consider giving me temporary and limited ssh access to the restricted vlatex directory so I could perform tests by myself much more quickly?

I'll get back to you when I have the debug class_vlatex.php.

For the record, if it helps somebody else, it was a LaTeX install issue, latex.fmt was missing. What finally solved the problem was to run:

Code:
fmtutil-sys --all
Reply With Quote
  #129  
Old 12-13-2012, 01:53 PM
emath emath is offline
 
Join Date: Sep 2008
Posts: 252
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Pod View Post
For the record, if it helps somebody else, it was a LaTeX install issue, latex.fmt was missing. What finally solved the problem was to run:

Code:
fmtutil-sys --all
ive done this, and find out that the latex.fmt file is in the: /.texmf-var/web2c/

and the mod requires it to be at : /.texmf/web2c/

so ive just copied the file to that directory ( using cp command ) .

thanks to pod for the help.

one more little thing : why does the \\ command for new line doesnt work?
Reply With Quote
  #130  
Old 12-13-2012, 02:10 PM
Pod Pod is offline
 
Join Date: Jun 2007
Posts: 129
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by emath View Post
and the mod requires it to be at : /.texmf/web2c/
Not specifically this mod, but your latex installation requires it to be there.

Quote:
Originally Posted by emath View Post
one more little thing : why does the \\ command for new line doesnt work?
LaTeX doesn't allow new lines in displayed equations. You can use one of amstex packages, for instance

[tex]\begin{gathered}
line 1 \\
line 2
\end{gathered}[/tex]
Reply With Quote
  #131  
Old 12-13-2012, 03:54 PM
emath emath is offline
 
Join Date: Sep 2008
Posts: 252
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

in mimetex it worked with no problem, and we wrote for years like this .
is there anyway to enable this command ?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:06 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.12666 seconds
  • Memory Usage 2,392KB
  • Queries Executed 26 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (4)bbcode_code
  • (2)bbcode_php
  • (8)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (11)post_thanks_box
  • (2)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_attachment
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete