summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/chemformula-ru/chemformula-ru.tex
blob: 02edcbca417266f1e47ebca30c8032b72c91bcdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
\documentclass[a4paper]{article}
\usepackage[]{geometry}
\geometry{total={180mm, 267mm}, centering}

\usepackage[russian]{babel}
\usepackage{chemformula}
\usepackage[ch2Ch,cosh2ch]{chemformula-ru}
\usepackage{array,multicol}

\begin{document}

\title{The \textsf{chemformula-ru} package}
\author{Alexey Kuznetsov}
\date{01.03.2024}
\maketitle

\begin{multicols}{2}
The \textsf{chemformula} package defines the command\\[.5ex]
\mbox{}\hfil\verb|\сh{|\textit{chemical formula}\verb|}|\\[.5ex]
to type up chemical formulas:\\[.5ex]
\mbox{}\hfil\verb|\ch{H3PO4}| $\to$ \ch{H3PO4}.\\[.5ex]
Russian settings of the \textsf{babel} package \textsf{(russianb.ldf)} define the same command to print the hyperbolic cosine:\\[.5ex] 
\mbox{}\hfil\verb|$\ch x$|\ $\to\ \Ch x$.\\[.5ex]
Loading packages together leads to the error\\[1ex]
\mbox{}\hfil\verb|! LaTeX Error: Command \ch already defined.|\\[1ex]
The \textsf{chemformula-ru} package ``neutralizes'' it by making the babel's command undefined.

The package has two parameters to configure the printing of the hyperbolic cosine in Russian notation:\\[1ex]
\begin{tabular}{>\sf l @{ ---\quad } p{.75\linewidth}}
cosh2ch & overrides the \verb|\cosh| command for printing:\linebreak
          \verb|$\cosh x$| $\to \cosh x$.  \\[1ex]
ch2Ch & defines a new \verb|\Ch| command for printing:\linebreak
         \verb|$\Ch x$| $\to \Ch x$.
\end{tabular}\\[1ex]

Пакет \textsf{chemformula} вводит команду\\[.5ex]
\mbox{}\hfil\verb|\сh{|\textit{химическая фоормула}\verb|}|\\[.5ex]
для верстки химических формул:\\[.5ex]
\mbox{}\hfil\verb|\ch{H3PO4}| $\to$ \ch{H3PO4}.\\[.5ex]
Русские настройки пакета \textsf{babel (russianb.ldf)} определяют одноименную команду для печати гиперболического косинуса:\\[-.5ex]
\mbox{}\hfil\verb|$\ch x$|\ $\to\ \Ch x$.\\[.5ex]
Cовместная загрузка пакетов ведет к ошибке\\[1ex]
\mbox{}\hfil\verb|! LaTeX Error: Command \ch already defined.|\\[1ex]
Пакет \textsf{chemformula-ru} <<нейтрализует>> ее, делая команду пакета \textsf{babel} неопределенной.

Пакет имеет два параметра, настраивающих печать гиперболического косинуса в русских нотациях:\\[1ex]
\begin{tabular}{>\sf l @{ --- } p{.8\linewidth}}
cosh2ch & переопределяет для печати команду \verb|\cosh|:\linebreak
          \verb|$\cosh x$| $\to \cosh x$.  \\[1ex]
ch2Ch & определяет для печати новую команду \verb|\Ch|:\linebreak
         \verb|$\Ch x$| $\to \Ch x$.
\end{tabular}
\end{multicols}

\noindent\hrulefill

\begin{verbatim}

%% Redefine \cosh to print ch.
\DeclareOption{cosh2ch}{\def\cosh@ch{%
                        \DeclareRobustCommand\cosh{\mathop{\operator@font ch}\nolimits}}}

%% Define new command \Ch to print ch.
\DeclareOption{ch2Ch}{\def\ch@Ch{%
                      \DeclareRobustCommand\Ch{\mathop{\operator@font ch}\nolimits}}}

\ProcessOptions\relax

\BeforeBeginEnvironment{document}{
   \IfPackageLoadedTF{chemformula}{ 
      \IfPackageLoadedWithOptionsTF{babel}{russian}{
         \let\@Chem@Formula\ch \let\ch\undefined
         \AtBeginDocument{ \let\ch\@Chem@Formula 
            \@ifundefined{cosh@ch}{\relax}{\cosh@ch}
            \@ifundefined{ch@Ch}{\relax}{\ch@Ch}
         } 
      } { \relax } 
   } { \relax }
}
\end{verbatim}

\end{document}