Skip to main content
edited tags
Link
edited tags
Link
Martin Sleziak
  • 56.5k
  • 9
  • 173
  • 308
Source Link
Nate Eldredge
  • 102.2k
  • 29
  • 33

The scope of \newcommand is the entire page

LaTeX on this site supports \newcommand and \renewcommand. This is very nice, but I noticed that the scope of these definitions is the entire rest of the page. That's consistent with how LaTeX behaves, but it could be undesirable on this site where the page contains posts by different people: one person's \newcommand affects everyone who posts below them.

To illustrate the problem, in this question I am including

\renewcommand{\sin}{\cos}

$\renewcommand{\sin}{\cos}$Now anyone who uses \sin in an answer or a comment will get $\cos$ instead.

(I considered exploiting this when asking some simple trig question on main and then watching the confusion, but decided not to be evil.)

It would be good if the scope of \newcommand and friends could be limited to the current question/answer/comment, but I don't know whether this is possible.