Giter Club home page Giter Club logo

math-delimiters's Introduction

math-delimiters

This package provides the command math-delimiters-insert to insert TeX/LaTeX math delimiters. This command is meant to be bound to $ in buffers where the user wants to use it. The author, for example, binds it in LaTeX-mode-map and in org-mode-map.

Note that the excellent cdlatex includes a cdlatex-dollar command that it binds to $. Users of both packages will probably want to unbind $ in cdlatex-mode-map.

The math-delimiters-insert command behaves as follows: if the region is active, it surrounds it with inline math delimiters and leaves the point after. Without an active region it inserts inline math delimiters and places point inside them. It toggles between display and inline if called from inside empty math delimiters, or just after math delimeters. (As a consequence, if called repeatedly it toggles between inline and display math.) A tiny bit of practice makes this very natural.

The delimiters used for inline math and display math by math-delimiters-insert are customizable, defaulting to \(...\) and \[...\] respectively. A command math-delimiters-toggle is provided to quickly toggle between $...$ and \(...\) for inline math and between $$...$$ and \[...\] for display math.

By default, inline math is translated into display math with no additional line breaks. This can be modified by setting math-delimiters-compressed-display-math to nil. For example, expression of the form \(...\) will then be translated to \n\[\n...\n\]\n.

When translating inline math to display math, often it is desirable to include punctuation into the display math and exclude it from of the inline math environment. For that purpose, the variable math-delimiters-include-characters is available; it is a string consisting of the punctuation characters to act upon. The default value is โ€œ,.;โ€. So, for example, toggling to display math on the expression \(\eta\). would turn it into \[\eta.\].

Finally, a command math-delimiters-no-dollars is provided to replace all $...$ and $$...$$ delimiters with \(...\) and \[...\], respectively. Sadly, this package offers no help convincing coauthors to use \(...\) over $...$.

Sample configuration

Put math-delimiters.el somewhere in your load-path and use something like this:

(autoload 'math-delimiters-insert "math-delimiters")

(with-eval-after-load 'org
  (define-key org-mode-map "$" #'math-delimiters-insert))

(with-eval-after-load 'tex              ; for AUCTeX
  (define-key TeX-mode-map "$" #'math-delimiters-insert))

(with-eval-after-load 'tex-mode         ; for the built-in TeX/LaTeX modes
  (define-key tex-mode-map "$" #'math-delimiters-insert))

(with-eval-after-load 'cdlatex
  (define-key cdlatex-mode-map "$" nil))

(Most people only use one out of AUCTeX and the built-in TeX/LaTeX modes, so you probably only need one of those forms.)

The above configuration will setup the $ key to insert math delimiters in both TeX and LaTeX buffers (because the LaTeX mode maps inherit from the TeX mode ones), if you only want to use it in LaTeX buffers you can use this instead:

(with-eval-after-load 'latex            ; for AUCTeX
  (define-key LaTeX-mode-map "$" #'math-delimiters-insert))

(with-eval-after-load 'tex-mode         ; for the built-in LaTeX mode
  (define-key latex-mode-map "$" #'math-delimiters-insert))

Notice that for the built-in LaTeX mode the feature is still tex-mode, not latex-mode.

math-delimiters's People

Contributors

oantolin avatar slotthe avatar david-vicente avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.