# Can a package overwrite the original commands in Latex?

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?

• isn't this identical to the question you just asked tex.stackexchange.com/questions/415590/… ? – David Carlisle Feb 16 '18 at 22:55
• The answer to the question in the title is "yes". The answer to number 2 is also "yes", see tex.stackexchange.com/questions/4515/…, 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
• 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

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}

$$x=4$$

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

$$x=4$$

\end{document}


• 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

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

For example save this as zzz.sty

\everypar{}
BOO!
\stop


\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.

\documentclass{article}
\usepackage{amsmath}

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

\begin{document}

equation
$$1=1$$

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.