2

I created an external reference file with many mathematical formulas. very similar to this: foonotes in external page the equations.tex is so structured :

\documentclass[10pt]{article}

\usepackage{amssymb,amsmath}
%\usepackage{catchfilebetweentags}
\usepackage{stackengine}  %% barbII
\usepackage{cancel}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage[overload]{empheq}
\newcommand{\for}{\text{for }}

\begin{document}
\begin{enumerate}
 \item \underline{\textit{Principio di conservazione della massa }}: 
%<*eq001>
\begin{center}
    \begin{equation}\label{eq001}
    \textbf{m} = \Intlim{V_{m}}\rho(x,t)\de{V} 
    \end{equation}
\end{center}
%</eq001>

%<*eq002>
\begin{center}
    \begin{equation}\label{eq002}
    \Dtot{m}{t} =\Dtot{}{t} \Intlim{V_{m}}\rho(x,t)\de{V}  = 0 
    \end{equation}
\end{center}
%</eq002>

\item \underline{\textit{Principio di bilancio della quantità di moto}} (Eulero, 1752):

%<*eq003>
\begin{center}
    \begin{equation}\label{eq003}
    \textbf{q}  = \Intlim{V_{m}}\rho\textbf{u}\de{V}  
    \end{equation}
\end{center}
%</eq003>
\end{enumerate}
\end{document}

enter image description here

In the preamble of the main.tex i inserted this:

\usepackage{catchfilebetweentags}
\newcommand{\loadeq}[1]{%
    \ExecuteMetaData[equations.tex]{eq#1}%
}

I call the various formulas in chapter01.tex with the loadeq {equation number} command :

bla bla bla bla bla bla bla 

\loadeq{003}

enter image description here

the problem is born if:

  • I want to align two equations; \loadeq{003} = \loadeq{003}
  • I want to align the equation and a text; ciao = \loadeq{003}
  • I want to align a particular symbol with the equation. $\vec{\Pi}=$ \loadeq{003} enter image description here

It would be interesting to understand how to be able to concatenate different \loadeq{arg}

enter image description here

Antonio
  • 543

1 Answers1

2

You should structure your equations. No need of catchfilebetweentags.

In the following, if you call \useeq*{<number>}, both sides of the saved equation are typeset; with \useeq{<number>}, only the right-hand side. In case of need, this could be easily augmented with \useeq[<side>]{<number>} where <side> is either l or r to print the left-hand side or the right-hand side.

\begin{filecontents}{antonio-equations}
\EQ{001}{
  \mathbf{p} = \Intlim{V_{m}}\rho(x,t)\de{V}
}
\EQ{002}{
  \Dtot{m}{t} = \Dtot{}{t} \Intlim{V_{m}}\rho(x,t)\de{V}
}
\EQ{003}{
  \mathbf{q} = \Intlim{V_{m}}\rho\mathbf{u}\de{V}
}
\end{filecontents}

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\EQ}{mm}
 {
  \prop_new:c { g_antonio_eq_#1_prop }
  \seq_set_split:Nnn \l__antonio_eq_temp_seq { = } { #2 }
  \prop_gput:cnx { g_antonio_eq_#1_prop }
   { l } { \seq_item:Nn \l__antonio_eq_temp_seq { 1 } }
  \prop_gput:cnx { g_antonio_eq_#1_prop }
   { r } { \seq_item:Nn \l__antonio_eq_temp_seq { 2 } }
 }
\NewDocumentCommand{\useeq}{sm}
 {
  \IfBooleanT { #1 }
   {
    \prop_item:cn { g_antonio_eq_#2_prop } { l } =
   }
  \prop_item:cn { g_antonio_eq_#2_prop } { r }
 }
\seq_new:N \l__antonio_eq_temp_seq
\ExplSyntaxOff

\newcommand{\de}[1]{\mathop{}\!d#1}
\newcommand{\Dtot}[2]{\frac{\de{#1}}{\de{#2}}}
\newcommand{\Intlim}[1]{\int\limits_{#1}}

\input{antonio-equations} % load the equations

\begin{document}

\begin{enumerate}
\item \textit{Principio di conservazione della massa}: 
\begin{gather}
\useeq*{001} \label{eq001}
\\
\useeq*{002}=0 \label{eq002}
\end{gather}

\item \textit{Principio di bilancio della quantità di moto} (Eulero, 1752):
\begin{equation}
\useeq*{003} \label{eq003}
\end{equation}

\item Combiniamo
\begin{align}
  \vec{\Pi} &= \useeq{001}
  \\
  x &= \useeq{003}
\end{align}

\end{enumerate}

\end{document}

Please, don't underline text in italic: double emphasis is too much and underlining is a frowned upon device among typographers.

enter image description here

Note also that you should never surround equation by center. And never should be taken in its literal sense. Also consecutive equation environments are to be avoided: amsmath offers a wealth of display environments.

egreg
  • 1,121,712
  • I was looking for this solution. this is very interesting. It's the first time I've written complete notes in LaTex and there's a lot to learn – Antonio Oct 20 '18 at 10:45
  • I could ask you for an explanation of all sequence of commands : \ExplSyntaxOn ....\prop...\seq....... \ExplSyntaxOff. how come it signals it as an unrecognized command? – Antonio Oct 23 '18 at 18:38
  • and have problems with commands \Aboxed. have a error : Misplaced alignment tab character &. \Aboxed{\barbII{\tau} =\useeqq*{010}}. I replaced with \boxed command, with this i dont'have problems – Antonio Oct 23 '18 at 18:58
  • @Antonio I can say nothing from this small snippet. – egreg Oct 23 '18 at 21:18
  • Regarding the first question (the explanation on the sequences of commands), it is the code that you put me. The second request, tomorrow I look if I can say more. – Antonio Oct 23 '18 at 21:33
  • @Antonio For the first question: update your TeX system. – egreg Oct 23 '18 at 21:37