From 46f34181e3dbbb691d3c9a7239b08e8665a994a4 Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Thu, 11 May 2017 16:03:37 -0400 Subject: [PATCH] Add \iff, \implies, \impliedby support. Fix #190. * Based on @ronkok's code, but without \mathrel as it's absent from amstex.sty. * Add toBuild tests to ensure these operators expand. --- src/macros.js | 9 +++++++++ test/katex-spec.js | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/macros.js b/src/macros.js index fb1054bf..ec7b90ce 100644 --- a/src/macros.js +++ b/src/macros.js @@ -21,3 +21,12 @@ defineMacro("\\endgroup", "}"); // \def\overset#1#2{\binrel@{#2}\binrel@@{\mathop{\kern\z@#2}\limits^{#1}}} defineMacro("\\overset", "\\mathop{#2}\\limits^{#1}"); defineMacro("\\underset", "\\mathop{#2}\\limits_{#1}"); + +//TODO: When implementing \dots, should ideally add the \DOTSB indicator +// into the macro, to indicate these are binary operators. +// \def\iff{\DOTSB\;\Longleftrightarrow\;} +// \def\implies{\DOTSB\;\Longrightarrow\;} +// \def\impliedby{\DOTSB\;\Longleftarrow\;} +defineMacro("\\iff", "\\;\\Longleftrightarrow\\;"); +defineMacro("\\implies", "\\;\\Longrightarrow\\;"); +defineMacro("\\impliedby", "\\;\\Longleftarrow\\;"); diff --git a/test/katex-spec.js b/test/katex-spec.js index 651df70e..caefcc0a 100644 --- a/test/katex-spec.js +++ b/test/katex-spec.js @@ -2012,12 +2012,18 @@ describe("A macro expander", function() { }); }); - it("should expand the \overset macro as expected", function() { + it("should expand the \\overset macro as expected", function() { expect("\\overset?=").toParseLike("\\mathop{=}\\limits^{?}"); expect("\\overset{x=y}{\sqrt{ab}}") .toParseLike("\\mathop{\sqrt{ab}}\\limits^{x=y}"); expect("\\overset {?} =").toParseLike("\\mathop{=}\\limits^{?}"); }); + + it("should build \\iff, \\implies, \\impliedby", function() { + expect("X \\iff Y").toBuild(); + expect("X \\implies Y").toBuild(); + expect("X \\impliedby Y").toBuild(); + }); }); describe("A parser taking String objects", function() {