4

I am using the catchfilebetweentags library to store equations in an external file and then import them into my document. This is useful when you need to use the same equation in multiple documents. This works for simple equations, but introduces an offset error when used with the multicols package. Does anyone know of a solution to this problem?

MWE

main.tex

\documentclass{article}
\usepackage{amsmath}
\usepackage{catchfilebetweentags}
\usepackage{multicol}

\newcommand{\loadeq}[1] {
    \ExecuteMetaData[./equations.tex]{eq#1}
}

\begin{document}

Loading equations from external file:
\loadeq{001}

Local equations:
\begin{multicols}{2}
    \begin{equation}
        \label{equ:X2}
        X = 
        \begin{bmatrix}
            X_0 \\
            X_1 \\
            X_2 \\
            X_3
        \end{bmatrix}
    \end{equation}

    \begin{equation}
        \label{equ:Y2}
        Y = 
        \begin{bmatrix}
            Y_0 \\
            Y_1 \\
            Y_2 \\
            Y_3
        \end{bmatrix}
    \end{equation}
\end{multicols}

\end{document}

equations.tex

\documentclass{article}
\begin{document}

%<*eq001>
\begin{multicols}{2}
    \begin{equation}
        \label{equ:X}
        X = 
        \begin{bmatrix}
            X_0 \\
            X_1 \\
            X_2 \\
            X_3
        \end{bmatrix}
    \end{equation}

    \begin{equation}
        \label{equ:Y}
        Y = 
        \begin{bmatrix}
            Y_0 \\
            Y_1 \\
            Y_2 \\
            Y_3
        \end{bmatrix}
    \end{equation}
\end{multicols}
%</eq001>

\end{document}

enter image description here

  • Welcome to TeX.SX! Very nicely laid out example! – egreg Jul 15 '15 at 13:17
  • @egreg Thanks; do you know how to embed the latex output? – Napthali Jul 15 '15 at 13:17
  • Just add a screen shot, I'll do it for you. – egreg Jul 15 '15 at 13:20
  • @egreg Thanks. Looks like you got the same output. – Napthali Jul 15 '15 at 13:22
4

The problem is that catchfilebetweentags ignores blank lines. If you remove the blank line in the “local” part, you get exactly the same.

Solution: use \par in the auxiliary file instead of a blank line.

\documentclass{article}
\begin{document}

%<*eq001>
\begin{multicols}{2}
    \begin{equation}
        \label{equ:X}
        X = 
        \begin{bmatrix}
            X_0 \\
            X_1 \\
            X_2 \\
            X_3
        \end{bmatrix}
    \end{equation}
\par
    \begin{equation}
        \label{equ:Y}
        Y = 
        \begin{bmatrix}
            Y_0 \\
            Y_1 \\
            Y_2 \\
            Y_3
        \end{bmatrix}
    \end{equation}
\end{multicols}
%</eq001>

\end{document}

enter image description here

However, using multicol to show equations side by side is not the best method, I'd go for two minipages.

|improve this answer|||||
  • Why do a I need a space between the equations? I see that it makes a difference, but don't understand why. – Napthali Jul 15 '15 at 13:40
  • @Napthali Actually, one should never have an equation environment immediately following a blank line or just after \begin{multicols}. That's why I suggest minipage. – egreg Jul 15 '15 at 13:41

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.