{"id":8,"date":"2014-10-16T04:06:19","date_gmt":"2014-10-16T04:06:19","guid":{"rendered":"http:\/\/www.aarondefazio.com\/tangentially\/?p=8"},"modified":"2014-10-16T04:06:19","modified_gmt":"2014-10-16T04:06:19","slug":"math-macros-the-best-feature-of-lyx-youre-not-using","status":"publish","type":"post","link":"https:\/\/www.aarondefazio.com\/tangentially\/?p=8","title":{"rendered":"Math Macros: The best feature of Lyx you&#8217;re not using"},"content":{"rendered":"<div id=\"globalWrapper\">\n<script type=\"math\/tex\">\n\\newcommand{\\lyxlock}{}\n<\/script><br \/>\n<noscript><\/p>\n<div class=\"warning\">\nWarning: <a href=\"http:\/\/www.mathjax.org\/\">MathJax<\/a> requires JavaScript to correctly process the mathematics on this page. Please enable JavaScript on your browser.\n<\/div>\n<hr\/>\n<p><\/noscript><\/p>\n<div class=\"Indented\">\n<\/div>\n<div class=\"Indented\">\nLyX is a brilliant tool for writing in the mathematical sciences. It provides a WYSIWYG style editor on top of LaTeX with just the right amount of abstraction for getting-stuff-done. With the proper setup, typing math into LyX is easier, faster and less error prone then using LaTeX directly, and it has virtually no down sides.\n<\/div>\n<div class=\"Indented\">\nPart of the setup is the use of use of LyX math macros. Math macros allow you to define new commands that you can use within LyX math mode. When writing pure LaTeX, most people include a set of standard macros in the header of the LaTeX documents. For example, a common one is a shortcut for argmin:\n<\/div>\n<div class=\"Indented\">\n<div class=\"center\">\n<div class=\"listing\">\n<pre class=\"listing\">\\newcommand{\\argmin}{\\operatornamewithlimits{argmin}}\r\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"Indented\">\nLyX math macros allow you to do the same thing within LyX.\n<\/div>\n<div class=\"Indented\">\nTo create the equivalent macro in LyX, create a new math macro\n<\/div>\n<div class=\"Indented\">\n<img decoding=\"async\" class=\"embedded\" src=\"InsertMathMacro.png\" alt=\"figure InsertMathMacro.png\" style=\"max-width: 495px; max-height: 492px;\"\/><\/p>\n<\/div>\n<div class=\"Indented\">\nThis will insert the following into your document:\n<\/div>\n<div class=\"Indented\">\n<img decoding=\"async\" class=\"embedded\" src=\"Macrobox.png\" alt=\"figure Macrobox.png\" style=\"max-width: 207px; max-height: 48px;\"\/><\/p>\n<\/div>\n<div class=\"Indented\">\nThis won\u2019t appear when you render out your document, so you can put it anywhere you like. To create the macro, just fill out the 3 parts. The first part is what you will type when using the macro, the second part is the LaTeX that will be output, and the third part controls what it looks like on screen within LyX. For most macros the TeX and LyX sections should be the same, for the argmin example we want the TeX code to produce a &ldquo;mathop&rdquo;, which LyX can\u2019t natively display. So we put a \\TeXtrm{argmin} in the LyX part. The filled in macro is thus:\n<\/div>\n<div class=\"Indented\">\n<img decoding=\"async\" class=\"embedded\" src=\"argmin.png\" alt=\"figure argmin.png\" style=\"max-width: 440px; max-height: 35px;\"\/><\/p>\n<\/div>\n<div class=\"Indented\">\nNote that for this to work you have to have amsmath package imported. To set that up, go Document -&gt; Settings&#8230;, then select the radio buttons under the math options section:\n<\/div>\n<div class=\"Indented\">\n<img decoding=\"async\" class=\"embedded\" src=\"amsmath.png\" alt=\"figure amsmath.png\" style=\"max-width: 839px; max-height: 540px;\"\/><\/p>\n<\/div>\n<div class=\"Indented\">\nTo use the macro, just type \\argmin within a LyX math box, then press space. It should insert the macro seemlessly. Within LyX the subscripts will look like:<span class=\"MathJax_Preview\"><br \/>\n<script type=\"math\/tex;mode=display\"><\/p>\n<p>\\text{argmin}_{x\\in\\mathbb{R}},<\/p>\n<p><\/script><\/p>\n<p><\/span><\/p>\n<\/div>\n<div class=\"Indented\">\nbut when you render it out to a pdf it will be typeset correctly as:<span class=\"MathJax_Preview\"><br \/>\n<script type=\"math\/tex;mode=display\"><\/p>\n<p>\\operatorname*{argmin}_{x\\in\\mathbb{R}}.<\/p>\n<p><\/script><\/p>\n<p><\/span><\/p>\n<\/div>\n<h2 class=\"Subsection-\">\n<a class=\"toc\" name=\"toc-Subsection--1\"><\/a>A few useful macros<br \/>\n<\/h2>\n<div class=\"Unindented\">\nI have the following macros setup in a lyx-math-macros.lyx file:\n<\/div>\n<div class=\"Indented\">\n<img decoding=\"async\" class=\"embedded\" src=\"AFewMacros.png\" alt=\"figure AFewMacros.png\" style=\"max-width: 266px; max-height: 153px;\"\/><\/p>\n<\/div>\n<div class=\"Indented\">\nThese macros illustrate the parameters feature as well. To add parameters to a macro, use the macro bar that appears at the bottom of the screen when editing the macro.\n<\/div>\n<div class=\"Indented\">\nI have a lyx template setup that I use for new documents. It includes a LyX sub-document include statement <img decoding=\"async\" class=\"embedded\" src=\"Include.png\" alt=\"figure Include.png\" style=\"max-width: 226px; max-height: 31px;\"\/><br \/>\nwhich gives access to the macros.\n<\/div>\n<h2 class=\"Subsection-\">\n<a class=\"toc\" name=\"toc-Subsection--2\"><\/a>How it\u2019s implemented<br \/>\n<\/h2>\n<div class=\"Unindented\">\nIf you convert your LyX document to a pdfLaTeX document, you\u2019ll see the following command is generated in the preamble\n<\/div>\n<div class=\"Indented\">\n<div class=\"listing\">\n<pre class=\"listing\">\\global\\long\\def\\argmin{\\operatornamewithlimits{argmin}}\r\n<\/pre>\n<\/div>\n<\/div>\n<div class=\"Indented\">\nThis uses lower level LaTeX commands then \\newcommand, but it has a similar effect . At the call site you\u2019ll see something like:\n<\/div>\n<div class=\"Indented\">\n<div class=\"listing\">\n<pre class=\"listing\">{argmin}_{x\\in \\mathbb{R}}\r\n<\/pre>\n<\/div>\n<\/div>\n<div class=\"Indented\">\nOther then the extra {} brackets, this is as simple as you could want.\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Warning: MathJax requires JavaScript to correctly process the mathematics on this page. Please enable JavaScript on your browser. LyX is a brilliant tool for writing in the mathematical sciences. It provides a WYSIWYG style editor on top of LaTeX with just the right amount of abstraction for getting-stuff-done. With the proper setup, typing math into &hellip; <a href=\"https:\/\/www.aarondefazio.com\/tangentially\/?p=8\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Math Macros: The best feature of Lyx you&#8217;re not using<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.aarondefazio.com\/tangentially\/index.php?rest_route=\/wp\/v2\/posts\/8"}],"collection":[{"href":"https:\/\/www.aarondefazio.com\/tangentially\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aarondefazio.com\/tangentially\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aarondefazio.com\/tangentially\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aarondefazio.com\/tangentially\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8"}],"version-history":[{"count":4,"href":"https:\/\/www.aarondefazio.com\/tangentially\/index.php?rest_route=\/wp\/v2\/posts\/8\/revisions"}],"predecessor-version":[{"id":18,"href":"https:\/\/www.aarondefazio.com\/tangentially\/index.php?rest_route=\/wp\/v2\/posts\/8\/revisions\/18"}],"wp:attachment":[{"href":"https:\/\/www.aarondefazio.com\/tangentially\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aarondefazio.com\/tangentially\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aarondefazio.com\/tangentially\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}