0

An example:

Without the amsmath package:

  1. The equation environment numbers the equation automatically.

  2. The align environment cannot be executed.

With the amsmath package:

  1. align and equation work seamlessly in numbering equations: I can use equation to write my first two equations, and align to write my third equation, and Latex will still number them correctly.

My questions are:

  1. Is the code for the command equation after loading the amsmath package still the same as it was before loading the package?

  2. Moreover, if this is the case, then, in general, can loading different packages cause conflicts? And how do we avoid it?

Torbjørn T.
  • 206,688
A Slow Learner
  • 377
  • 1
  • 3
  • 9
  • 3
    isn't this identical to the question you just asked https://tex.stackexchange.com/questions/415590/how-does-latex-compilers-integrate-packages-into-its-existing-core-functions ? – David Carlisle Feb 16 '18 at 22:55
  • 2
    The answer to the question in the title is "yes". The answer to number 2 is also "yes", see https://tex.stackexchange.com/questions/4515/whats-the-right-order-when-loading-packages?rq=1, or rather the duplicate question, and the "Linked" questions in the right margin. – Torbjørn T. Feb 16 '18 at 22:55
  • @DavidCarlisle I don't think they are truly identical. The previous question was broader and is not a yes/no question. It also did not have anything similar to the second part of this question. Finally, this question is more about me confirming my understanding of how Latex handles packages, in this particular context. However, please correct if I am wrong. I am thinking of removing the previous question anyway since nobody has given me an answer so far due to a lot of incorrect statements made in that question. – A Slow Learner Feb 16 '18 at 23:04
  • 2
    I can't see any difference to be honest. As already stated in answers and comments on the previous question a package can redefine absolutely any part of latex. No harm of course to remove the older question if you think this one is phrased better. – David Carlisle Feb 16 '18 at 23:06
  • @TorbjørnT. Thank you. How about the answer to number 1? (I know the answer to the title is yes, but number 1 is a bit different from the title). – A Slow Learner Feb 16 '18 at 23:07
  • the answer to q1 is that amsmath redefines equation (but that is unrelated to the comments you make about numbering – David Carlisle Feb 16 '18 at 23:08
  • @DavidCarlisle Wouldn't it have to redefine equation in order for equation to work with align seamlessly? – A Slow Learner Feb 16 '18 at 23:11
  • no not at all, it just needs to use the same equation counter (the redefinition is for other reasons, to make it work with subequation and as you noted before to adjust things so \nonumber (which is defined in core latex but only affects eqnarray) also affects equation. – David Carlisle Feb 16 '18 at 23:13
  • @DavidCarlisle Thank you for your explanation. Now I understand a bit more about how Latex works. Hopefully, I will not have to post more trivial questions like this one and the other. – A Slow Learner Feb 16 '18 at 23:19

2 Answers2

4

Everyone can redefine commands or environments. Such a redefinition changes the code. This can lead to conflicts or unwanted side effects. But normally package writers know this and try to avoid such conflicts -- after all nobody is forced to use a package that doesn't behave and break other code.

\documentclass{article}

\usepackage{xcolor}

\begin{document}

\begin{equation}
x=4
\end{equation}

\renewenvironment{equation}
{\par\color{red}\Huge\centering}
{\par}

\begin{equation}
x=4
\end{equation}

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • Ow, it hurts my eyes!!! Not because the size or color, but because equation not in math mode :) – Sigur Feb 16 '18 at 23:45
3

A package can redefine any part of latex and produce arbitrary outcomes.

For example save this as zzz.sty

\everypar{}
BOO!
\stop

and add

\usepackage{zzz}

to any latex document.

The fact the equation and align number in sequence does not require a redefinition of either enviornment, this document defines a new envioenment zzz that numbers in the same sequence but does not redefine either equation or align.

enter image description here

\documentclass{article}
\usepackage{amsmath}

\newenvironment{zzz}
{\par\refstepcounter{equation} \fbox{this is \theequation zzz}}
{zzz ends here\par}

\begin{document}

equation
\begin{equation}
  1=1
\end{equation}

zzz
\begin{zzz}
  qqq
\end{zzz}

align
\begin{align}
  a&=1\\
b&=2
\end{align}
\end{document}

Packages can have irreconcilable conflicts if package a defines \zzz to be red and package b defines \zzz to be blue then you clearly can not have both packages working at the same time. If you load both packages depending on the implementation details you may get an error or you may get red or blue depending on package loading order. It is up to the author of the document to load the packages that are needed and not to load packages that conflict.

David Carlisle
  • 757,742