Graphics, Figures & TablesLewis Diagram inside chemical Structure

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
MatthiasN
Posts: 41
Joined: Sun Mar 11, 2012 1:21 pm

Lewis Diagram inside chemical Structure

Post by MatthiasN »

Hi everyone,

I'm busy trying to figure out chemfig. I came across an example that doesn't seem to work. I've checked, but it's not because I forgot to load a certain package or something. The example is:

Code: Select all

\documentclass{report}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage {chemfig}
\usetikzlibrary{decorations}

\chemfig{H-\chemabove{\lewis{5|7,O}}{\quad\scriptstyle +}(-[2]H)-H}
I did get this code to work when I put just O for the first argument of \chemabove{}{}. So the problem seems to be using the\lewis{} command inside the first argument. But this is what is done in the package documentation...

Thanks for reading and hopefully someone can help me.
Regards,
Matthias

Recommended reading 2024:

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

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

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Lewis Diagram inside chemical Structure

Post by localghost »

We would appreciate it very much if you could get used to always providing a self-contained and minimal example. We don't want to ask for that in every thread you open.

Perhaps you need an update at least of chemfig. I have no problem with this example. The output is attached.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{chemfig}

\begin{document}
  \chemfig{H-\chemabove{\lewis{5|7,O}}{\quad\scriptstyle +}(-[2]H)-H}
\end{document}
If you get errors or warnings, please extract them from the log file and post them here. That's part of an adequate problem description.


Thorsten
Attachments
tmp.png
tmp.png (824 Bytes) Viewed 10256 times
MatthiasN
Posts: 41
Joined: Sun Mar 11, 2012 1:21 pm

Lewis Diagram inside chemical Structure

Post by MatthiasN »

I appologize, I realize that I make a habbit of forgetting stuff in my minimal example. I've tried your the example on it self and it worked.

Code: Select all

\documentclass{report}
\usepackage{chemfig}

\begin{document}
\chemfig{H-\chemabove{\lewis{5|7,O}}{\quad\scriptstyle +}(-[2]H)-H}
\end{document}
Strange thing is, it doesn't work when I try it in the document I'm currently working in... It renders the following error:

Code: Select all

Missing number, treated as zero ...wis{5|7,O}}{\quad\scriptstyle +}(-[2]H)-H}
I've tried to take out the other packages, so that the ones that are loaded are identical to the one in the example above that does work and it stills yields the same error. Since I am able to produce the right output, I don't believe that my version of chemfig is outdated. Just to be sure, I updated it anyway. This didn't solve my problem either.

Hopefully you can get any wiser from the error. If not I will post some of the preceding lines.

Regards,
Matthias
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Lewis Diagram inside chemical Structure

Post by localghost »

MatthiasN wrote:[…] I've tried to take out the other packages, so that the ones that are loaded are identical to the one in the example above that does work and it stills yields the same error. […]
That's the purpose of a minimal example. Cutting the document down to the content that still produces the error. And that's the example you can post here.
MatthiasN wrote:[…] Hopefully you can get any wiser from the error. If not I will post some of the preceding lines. […]
Unfortunately not. The error alone is not very helpful. So, create the minimal code that reproduces the error, add the \listfiles command as very first line and compile it. Post this example here and attach the generated log file by upload to the forum server.

Perhaps there is a package that's loaded after chemfig and might overwrite some of its macros to its disadvantage. But more can only be said if we can see it.
MatthiasN
Posts: 41
Joined: Sun Mar 11, 2012 1:21 pm

Lewis Diagram inside chemical Structure

Post by MatthiasN »

I found out which command triggers the error. Before I tried this example I was trying out some setting with \setlewis[]{}{}{}. Afterwards, I used this command with all fields empty to restore to default settings.

Code: Select all

\listfiles
\documentclass{report}
\usepackage{amsmath}
\usepackage{chemfig}

\begin{document}
\setlewis[]{}{}{}
\chemfig{H-\chemabove{\lewis{5|7,O}}{\quad\scriptstyle +}(-[2]H)-H}
\end{document}
The \setlewis command with the empty fields seems to be what is causing the error. I also attached the log file in case you still need it.
Attachments
Minimal_example.log
(50.57 KiB) Downloaded 401 times
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Lewis Diagram inside chemical Structure

Post by localghost »

MatthiasN wrote:[…] Before I tried this example I was trying out some setting with \setlewis[]{}{}{}. Afterwards, I used this command with all fields empty to restore to default settings. […]
The default settings can be found on page 29 of the chemfig manual.

Code: Select all

\setlewis{0.2ex}{1.5ex}{}
If you need this several times, define some kind of "reset" switch (in the preamble).

Code: Select all

\newcommand*{\resetlewis}{\setlewis{0.2ex}{1.5ex}{}}
MatthiasN
Posts: 41
Joined: Sun Mar 11, 2012 1:21 pm

Re: Lewis Diagram inside chemical Structure

Post by MatthiasN »

I know where to find the standard values, because that is where I also read that you can also restore the standard values by just leaving the arguments empty. But nevermind, I'll just put them in there.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Lewis Diagram inside chemical Structure

Post by localghost »

Then somehow the command seems not to work correctly or it's the empty optional argument that causes the problem. Perhaps try again by omitting the optional argument and only giving empty mandatory arguments.

Code: Select all

\setlewis{}{}{}
MatthiasN
Posts: 41
Joined: Sun Mar 11, 2012 1:21 pm

Re: Lewis Diagram inside chemical Structure

Post by MatthiasN »

Yes, that works. Thanks.
Post Reply