LaTeX forum ⇒ Math & ScienceBabel problem with chemfig (and possibly other packages) Topic is solved

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
drml
Posts: 2
Joined: Mon May 20, 2013 2:17 pm

Babel problem with chemfig (and possibly other packages)

Postby drml » Mon May 20, 2013 2:50 pm

Hello everyone,

I just want to share a solution to a problem, which had been driving me mad for some time.

I've benn using Lyx for a while, when I came across a neat package called chemfig, which is great for chemical diagrams. Unfortunatly, some of its features, which was using parentesis arguments were unavalible - the code won't compile:

\documentclass[oneside,czech]{book}
\usepackage{babel}
\usepackage{chemfig}

\begin{document}

\schemestart
A \arrow(aa--bb) B
\schemestop

\end{document}


Error:
! Paragraph ended before \CF@arrow@i was complete.

It took me a while to find out what is causing this problem: Babel and its shorthnads. According to the babel documentation, there's a hypen (-) defined as shorthand character. This applies by default to Czech and Slovak languages. Therefore babel misinterprets chemfig arguments and the command seems to be unfinished (at least I think so ;) ).

The solution si quite simple: use babel commands to turn off the shorthand teporarily for the chemfig block:

\documentclass[oneside,czech]{book}
\usepackage{babel}
\usepackage{chemfig}

\begin{document}

\shorthandoff{-}
\schemestart
A \arrow(aa--bb) B
\schemestop
\shorthandon{-}

\end{document}


Works like a charm :D

Because I'm new to LaTeX, please excuse the crudeness of my solution. I just wanted to help those with similar problem. If there is a better/more elegant solution, I would be pleased to see it.

Recommended reading 2021:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics
User avatar
cgnieder
Site Moderator
Posts: 2001
Joined: Sat Apr 16, 2011 7:27 pm

Babel problem with chemfig (and possibly other packages)  Topic is solved

Postby cgnieder » Mon May 20, 2013 3:37 pm

Hi drml,

Welcome to the LaTeX community! Thanks for sharing your experiences.

drml wrote:Because I'm new to LaTeX, please excuse the crudeness of my solution. I just wanted to help those with similar problem. If there is a better/more elegant solution, I would be pleased to see it.


There's nothing crude about your solution. It's maybe a bit more convenient, though, to patch the \schemestart and \schemestop commands. That way you don't need to repeatedly turn the shorthand off and on again.

\documentclass[oneside,czech]{book}
\usepackage{babel}
\usepackage{chemfig}

\usepackage{etoolbox}
\pretocmd\schemestart{\shorthandoff{-}}{}{}
\apptocmd\schemestop{\shorthandon{-}}{}{}

\begin{document}

\schemestart
A \arrow(aa--bb) B
\schemestop

\end{document}


Regards
site moderator & package author

drml
Posts: 2
Joined: Mon May 20, 2013 2:17 pm

Re: Babel problem with chemfig (and possibly other packages)

Postby drml » Mon May 20, 2013 3:52 pm

Hi cgnieder,

Thanks a lot - that's what I call an elegant solution! :D

Best regards


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 4 guests