Math & ScienceBabel problem with chemfig (and possibly other packages)

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

Babel problem with chemfig (and possibly other packages)

Post by drml »

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:

Code: Select all

\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:

Code: Select all

\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 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Babel problem with chemfig (and possibly other packages)

Post by cgnieder »

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.

Code: Select all

\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)

Post by drml »

Hi cgnieder,

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

Best regards
Post Reply