Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Can anyone ples help with this problem:

\documentclass[fontsize=12pt,paper=a4,headsepline]{scrartcl}  
\usepackage{chemfig,chemmacros}  
\def\nc{\arrow{0}[,0]}  

\begin{document}  
What it is:  
\schemedebug{true}  
\schemestart  
\chemfig{A}  
\chemsign{+}  
\chemfig{A}  
\arrow{->}  
\chemfig{C}  
\schemestop  

What I want:  
\schemedebug{true}  
\schemestart  
\chemfig{A}\arrow{0}[,0]  
\chemsign{+}\arrow{0}[,0]  
\chemfig{A}  
\arrow{->}  
\chemfig{C}  
\schemestop  

the usage of arrow{0}[,0] is very annoying, so I tried this:  
%\schemedebug{true}  
%\schemestart  
%\chemfig{A}\nc  
%\chemsign{+}\nc  
%\chemfig{A}  
%\arrow{->}  
%\chemfig{C}  
%\schemestop  
\end{document}  

But all I get is this error:

%! Undefined control sequence.
<recently read> \node
share|improve this question
1  
Note to readers: it is the commented section of code that causes the error. –  Steven B. Segletes Apr 21 at 13:17

1 Answer 1

up vote 3 down vote accepted

Inside a scheme (i.e. between \schemestart and \schemestop) the \arrow commands needs to be used directly and not hidden in a macro. But there are other possibilities.

In order to use your \nc macro as a shortcut for \arrow{0}[,0] chemfig's scheme mechanism must treat it like it treats \arrow. That can be achieved rather easily by patching \CF@schemestart@v. Currently it looks for the tokens \arrow, merge and \schemestop and collects all other macros as part of the node (or “compound”) text. With the help of etoolbox's \patchcmd the macro \nc can be added to the list:

\makeatletter
\patchcmd\CF@schemestart@v
  {\arrow}%    search
  {\arrow\nc}% replace
  {}%          success
  {}%          failure
\makeatother

Then \nc can be used as the shortcut you want:

\documentclass[fontsize=12pt,paper=a4,headsepline]{scrartcl}  
\usepackage{chemfig,etoolbox}

\newcommand\nc{\arrow{0}[,0]}

\makeatletter
\patchcmd\CF@schemestart@v
  {\arrow}%    search
  {\arrow\nc}% replace
  {}%          success
  {}%          failure
\makeatother

\begin{document}  
\schemedebug{true}

\schemestart
  \chemfig{A}\nc
  \chemsign{+}\nc
  \chemfig{A}
  \arrow{->}
  \chemfig{C}
\schemestop

\end{document}

enter image description here


Original answer that assumed that the question was about spacing:

I'd use chemfig's \+ instead of \chemsign{+}. The latter was introduced before chemfig had the possibilities for schemes. The \+ is designed to be used inside schemes and it is possible to set the spacing before and after the + it typesets with

\setandsign{<dim before>}{<dim after>}{<vertical offset>}

This can also be adjusted on a per case basis as \+ has an optional argument (with braces!):

\+{<dim before>,<dim after>,<vertical offset>}

The macro is described in the manual in part IV Reaction schemes section 12 The + sign.

Also keep in mind that everything between two \arrow commands is placed in one node. Inside a node ends of lines will be treated as spaces like everywhere else in LaTeX:

\schemestart
  % first node:
  \chemfig{A}
  \chemsign{+}
  \chemfig{A}
  \arrow{->}
  % second node:
  \chemfig{A}%  hide end of line
  \chemsign{+}% hide end of line
  \chemfig{A}
\schemestop

enter image description here

Using \+:

\schemestart
  \chemfig{A}
  \+
  \chemfig{A}
  \arrow{->}
  \chemfig{C}
\schemestop

\schemestart
  \chemfig{A}%
  \+%
  \chemfig{A}
  \arrow{->}
  \chemfig{C}
\schemestop

\setandsign{0pt,0pt,0pt}
\schemestart
  \chemfig{A}%
  \+%
  \chemfig{A}
  \arrow{->}
  \chemfig{C}
\schemestop

enter image description here

share|improve this answer
    
What prevents the use of \arrow in a macro? –  Ian Thompson Apr 21 at 15:02
    
(I haven't looked too closely into the source of chemfig so the following may actually be wrong) The scheme commands look for the token \arrow and if it is inside a macro it is not found and as a consequence collected as part of the node text. Instead it should end the current node and start a new one... –  cgnieder Apr 21 at 15:11
    
I know about the \+, but its annoying to center the + in every reaction with the vertical offset. If it's possible to make the + a stand alone compound by default the code for long reaction schemes would be much more nicer. (that was my intention with \arrow{0}[,0]) –  flamel Apr 21 at 16:10
    
@flamel that wasn't clear from your question! I assumed you wanted to reduce the spacing (which was the only visual difference in the outcome of you MWE).... –  cgnieder Apr 21 at 16:34
    
@flamel please see my edited answer –  cgnieder Apr 21 at 16:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.