LateX for chemistry

LateX for chemistry

by Gino Palmia -
Number of replies: 3

Hi all,

I am a chemistry teacher and I should like to use LateX notation for chemistry in moodle (usually I use \chemfig).

Does someone use this package for drawing molecules?

How (if it is) is possible to enable moodle to this package?

Thank you for the answer...


Average of ratings: -
In reply to Gino Palmia

Re: LateX for chemistry

by Jitender Madan -

I have enabled chemfig support on my localhost Moodle (Version 3.10) installation running with Apache 2.4.29, MySQL 5.7.33, PHP 7.2.34, Ghostscript 9.26, Tex 3.14 (Tex Live 2017)  on elementary OS 5.1 ) using below steps. It is working fine.

1. Disable Mathjax Filter and Enable Tex Filter in Administration > Site administration > Plugins > Filters > Manage filters

2. Ensure Ghostscript and TexLive with chemfig package is installed on machine on which Moodle is running. I have installed texlive-full on my machine.

3. Update Latex Renderer Settings in Administration > Site administration > Plugins > Filters > Tex Notation. 

a. In LaTeX preamble add text \usepackage{chemfig} and also append the chemfig in in \RequirePackage declaration. 

b. On the same settings page --> Ensure path to latex, dvips, convert, dvisvgm is correctly detected. 

Now chemfig package can be used by declaring LaTeX math environment. If there occurs some error, enable the DEVELOPER mode on debugger (Administration > Site administration > Development>Debugging).  

In my case, Tex was making dvi file correctly, but there was error when converting to png or svg. So by following the debugger messages, I modified the two lines of code in required file.  I have not documented the modification, but that should be easier to find with debugger enabled.

Reference Document: https://docs.moodle.org/310/en/TeX_notation_filter


Attachment Chemfig.png
Attachment Editor.png
Average of ratings: Useful (1)
In reply to Jitender Madan

Re: LateX for chemistry

by Jitender Madan -
Modification was in file moodle > filter > tex > latex.php. Removed flag -E from following two lines of code:

$command = "$pathdvips -q -E $dvi -o $ps";
$command = "$pathdvisvgm -E $ps -o $img";

Details of option flags can be seen here.
Average of ratings: Useful (1)
In reply to Jitender Madan

Re: LateX for chemistry

by Jitender Madan -
Previously I had not documented one error in getting chemfig working in Moodle. Recenly, I was deploying the Moodle for my College and same problem resurfaced.
Conversion of ps to PNG/GIF fails because of default policy setting of ImageMagick for Ghostscript related files on UBUNTU based systems, and following error occurs
> attempt to perform an operation not allowed by the security policy ; > no images defined `test-%02.png' @ error/convert.c/ConvertImageCommand/3258. 

Edit /etc/ImageMagick-XX/policy.xml and change

<policy domain="coder" rights="none" pattern="PS" />
to
<policy domain="coder" rights="read|write" pattern="PS" />


Reference Page : https://legacy.imagemagick.org/discourse-server/viewtopic.php?t=35300