1

I'm using chemfig to create some structural formulas, but I need to create a new environment, like equation, that have a dedicated index and reference counter. I'm searching about this, but I'm having some difficult to get something that works for me.

For example, I would like somenthing like:

text text text text~\ref{eq:foo} 

\begin{equation}
    a = b
    \label{eq:foo}
\end{equation}

text text text text~\ref{sf:foo}   

\begin{structuralFormula}
    H_{2}O
    \label{sf:foo}
\end{structuralFormula}

text text text text~\ref{eq:bar} 

\begin{equation}
    h^2 = c_1^2 + c_2^2
    \label{eq:bar}
\end{equation}

text text text text~\ref{sf:bar} 

\begin{structuralFormula}
    \chemfig{
        C(
        -[:0]H
        )(
        -[:90]H
        )(
        -[:180]H
        )(
        -[:270]H
        )
    }
    \label{sf:bar}
\end{structuralFormula}

enter image description here

I.e., I need a new environment, that works exactly like equation and that have a new index entry, dedicated only to this new environment. I calling the numbers as index entry, but I realy don't know if this is the correct technical name.

I already have something like this:

\documentclass[
    12pt,               % tamanho da fonte
    openright,          % capítulos começam em pág ímpar (insere página vazia caso preciso)
    twoside,            % para impressão em verso e anverso. Oposto a oneside
    a4paper,            % tamanho do papel. 
    chapter=TITLE,      % títulos de capítulos convertidos em letras maiúsculas
    section=TITLE,      % títulos de seções convertidos em letras maiúsculas
    english,            % idioma adicional para hifenização
    french,             % idioma adicional para hifenização
    spanish,            % idioma adicional para hifenização
    brazil,             % o último idioma é o principal do documento
]{abntex2}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lastpage}   
\usepackage{indentfirst}
\usepackage[final]{graphicx}
\usepackage{microtype}      
\usepackage{hyperref}
\usepackage{subfig}
\usepackage{epigraph}
\usepackage{url}
\usepackage{placeins}
\usepackage{multirow}
\usepackage[figuresright]{rotating}
\usepackage{chemfig}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{enumitem}
\usepackage{environ}

\makeatletter
\hypersetup{
    colorlinks=true,        
    linkcolor=black,        
    citecolor=black,        
    filecolor=black,        
    urlcolor=black,
    bookmarksdepth=4
}
\makeatother



\NewEnviron{structuralFormula}{%
    \begin{equation}
    \BODY
    \end{equation}
}



\begin{document}

    text text text text~\ref{eq:foo} 

    \begin{equation}
        a = b
        \label{eq:foo}
    \end{equation}

    text text text text~\ref{sf:foo}  

    \begin{structuralFormula}
        H_{2}O
        \label{sf:foo}
    \end{structuralFormula}

    text text text text~\ref{eq:bar} 

    \begin{equation}
    h^2 = c_1^2 + c_2^2
    \label{eq:bar}
    \end{equation}

    text text text text~\ref{sf:bar}

    \begin{structuralFormula}
        \chemfig{
            C(
            -[:0]H
            )(
            -[:90]H
            )(
            -[:180]H
            )(
            -[:270]H
            )
        }
        \label{sf:bar}
    \end{structuralFormula}

\end{document}

That generates this:

enter image description here

But I want the numbers like the first picture.

4
  • Please post a compilable document, not only fragments. With index you mean something like a \listofstructuralformula? – user31729 Jun 27 '16 at 16:52
  • @ChristianHupfer Done. A way to make a list would be nice, but I need separate numbers for equation and the new environment. Take a look now, with my document. I post the result too. – davidbuzatto Jun 27 '16 at 16:59
  • 1
    not meaning to be discouraging, but won't using the same numbers for both be confusing to a reader? (maybe using a prefix for one or the other would be useful in that respect.) – barbara beeton Jun 27 '16 at 17:34
  • @barbarabeeton: That's a good idea. I think, I will rework my solution – user31729 Jun 27 '16 at 19:26
1

A preliminary version with article instead of abntex2 (that one fails!)

\documentclass{article}
\usepackage{tocloft}
\usepackage{chemfig}
\usepackage{environ}



\newcommand{\listofstructformname}{List of structural formulas}

\newlistof{structform}{stf}{\listofstructformname}

\makeatletter
\NewEnviron{structuralFormula}[1]{%
  \let\c@equation\c@structform
  \renewcommand{\theHequation}{structform.\theequation}
  \begin{equation}
    \BODY
    \addcontentsline{stf}{section}{\protect\numberline{\theequation}#1}
  }[%
\end{equation}
]
\makeatother


\usepackage{hyperref}

\hypersetup{%
    colorlinks=true,        
    linkcolor=black,        
    citecolor=black,        
    filecolor=black,        
    urlcolor=black,
    bookmarksdepth=4
}



\begin{document}
\listofstructform

\clearpage
text text text text~\ref{eq:foo} 

\begin{equation}
    a = b
    \label{eq:foo}
\end{equation}

text text text text~\ref{sf:foo}   

\begin{structuralFormula}{Water}
    H_{2}O
    \label{sf:foo}
\end{structuralFormula}

text text text text~\ref{eq:bar} 

\begin{equation}
    h^2 = c_1^2 + c_2^2
    \label{eq:bar}
\end{equation}

text text text text~\ref{sf:bar} 

\begin{structuralFormula}{Something I don't know}
    \chemfig{
        C(
        -[:0]H
        )(
        -[:90]H
        )(
        -[:180]H
        )(
        -[:270]H
        )
    }
    \label{sf:bar}
\end{structuralFormula}

\end{document}

Update Due to the pecularities of abntex2 (it's based on memoir), the easy setup with tocloft does not work -- the list has to be setup manually.

\documentclass[
12pt,               % tamanho da fonte
openright,          % capítulos começam em pág ímpar (insere página vazia caso preciso)
twoside,            % para impressão em verso e anverso. Oposto a oneside
a4paper,            % tamanho do papel. 
chapter=TITLE,      % títulos de capítulos convertidos em letras maiúsculas
section=TITLE,      % títulos de seções convertidos em letras maiúsculas
english,            % idioma adicional para hifenização
french,             % idioma adicional para hifenização
spanish,            % idioma adicional para hifenização
brazil,             % o último idioma é o principal do documento
]{abntex2}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lastpage}   
\usepackage{indentfirst}
\usepackage[final]{graphicx}
\usepackage{microtype}      
\usepackage{subfig}
\usepackage{epigraph}
\usepackage{url}
\usepackage{placeins}
\usepackage{multirow}
\usepackage[figuresright]{rotating}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{enumitem}



\usepackage{chemfig}
\usepackage{environ}



\newcommand{\listofstructformname}{List of structural formulas}

\makeatletter
\newcounter{structform}
\newcommand{\listofstructform}{%
  \begingroup
  \let\contentsname\listofstructformname
  \let\latex@@starttoc\@starttoc
  \def\@starttoc##1{\latex@@starttoc{stf}}
  \tableofcontents
  \endgroup
}

\NewEnviron{structuralFormula}[1]{%
  \let\c@equation\c@structform
  \renewcommand{\theHequation}{structform.\theequation}% Make hyperref happy!
  \renewcommand{\@currentlabelname}{#1}% Make nameref working
  \begin{equation}
    \BODY
    \addcontentsline{stf}{section}{\protect\numberline{\theequation}#1}
  }[%
\end{equation}
]
\makeatother

\usepackage{hyperref}

\hypersetup{%
    colorlinks=true,        
    linkcolor=black,        
    citecolor=black,        
    filecolor=black,        
    urlcolor=black,
    bookmarksdepth=4
}



\begin{document}
\tableofcontents
\clearpage
\listofstructform

\clearpage
text text text text~\ref{eq:foo} 

\begin{equation}
    a = b
    \label{eq:foo}
\end{equation}

text text text text~\ref{sf:foo}   

\begin{structuralFormula}{Water}
    H_{2}O
    \label{sf:foo}
\end{structuralFormula}

text text text text~\ref{eq:bar} 

\begin{equation}
    h^2 = c_1^2 + c_2^2
    \label{eq:bar}
\end{equation}

text text text text~\ref{sf:bar} 

\begin{structuralFormula}{Something I don't know}
    \chemfig{
        C(
        -[:0]H
        )(
        -[:90]H
        )(
        -[:180]H
        )(
        -[:270]H
        )
    }
    \label{sf:bar}
\end{structuralFormula}

\end{document}

enter image description here

4
  • That worked like a charm! Thank you very much! – davidbuzatto Jun 27 '16 at 17:33
  • @davidbuzatto: You're welcome! Happy TeXing! – user31729 Jun 27 '16 at 17:36
  • memoir has \newlistof – egreg Jun 27 '16 at 22:30
  • @egreg: I know, but compiling with abntex2 reports \listofstructform to be unknown then. – user31729 Jun 28 '16 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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