我正在使用 [version=4]{mhchem} 和fancyref
作为包。在mchem
的手册中,给出了序言的代码,可以像正常方程一样轻松地列举化学方程式:
\makeatletter
\newcommand\reaction@[1]{\begin{equation}\ce{#1}\end{equation}}
\newcommand\reaction@nonumber[1]%
{\begin{equation*}\ce{#1}\end{equation*}}
\newcommand\reaction{\@ifstar{\reaction@nonumber}{\reaction@}}
\makeatother
因为我想标记这些方程式以便引用它们,所以我将第二行改为\newcommand\reaction@[2]{\begin{equation}\ce{#1}\end{equation} \label{eq:#2}}
主要工作。但是当我引用它们时,\fref{eq:label}
它们具有放置方程式的章节.部分.子部分的编号,而不是方程式后面给出的编号。当我改用代码时,\begin{equation}\ce{Formula}\label{eq:Formula}\end{equation}
引用工作正常,我得到了方程式的编号。
有人能帮我看看我修改序言的地方哪里错了吗?
这是一个简单的例子:
\documentclass[12pt, a4paper, twoside, openright]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[english,ngerman]{babel}
\usepackage[version=4]{mhchem}
\usepackage{fancyref}
\makeatletter
\newcommand\reaction@[2]{\begin{equation}\ce{#1}\end{equation}\label{eq:#2}}
\newcommand\reaction@nonumber[1]%
{\begin{equation*}\ce{#1}\end{equation*}}
\newcommand\reaction{\@ifstar{\reaction@nonumber}{\reaction@}}
\makeatother
\begin{document}
\chapter{Fuel Cell}
\section{General}
\subsection{Fundamentals}
The basic reaction of a hydrogen fuel cell is very simple, as \fref{eq:FC} shows. To gain electric energy these reaction must be separated into the hydrogen oxidation reaction (HOR, \fref [plain]{eq:HOR}) which occurs at the >anode and the oxygen reduction reaction (ORR, \fref[plain]{eq:ORR}) at the >cathode. To maintain electroneutrality, the negative current flow has to be >compensated via ionic cunduction between the electrodes. For this an >electrolyte has to be chosen which is electronically insulating but >ionically conductive.
\reaction{H2 + 1/2O2 -> H2O}{FC}
\reaction{H2 -> 2H+ + 2e-}{HOR}
\begin{equation}\ce{1/2O2 + 2e- -> O^2-}\label{eq:ORR}\end{equation}
\end{document}
答案1
尝试
\newcommand\reaction@[2]{\begin{equation}\ce{#1}\label{eq:#2}\end{equation}}
也就是说,将其放在\label
你的定义中的方程中,就像你写的那样
\begin{equation}\ce{1/2O2 + 2e- -> O^2-}\label{eq:ORR}\end{equation}