Giter Club home page Giter Club logo

latex-math-input's Introduction

LaTeX Math Input

Motivation

I often need to type LaTeX math in LaTeX or Markdown documents. And while typing LaTeX is actually pretty easy, inputting a lot of LaTeX math on a regular basis can soon become a cumbersome and time-consuming task.

Inspired by this blog post I came up with the following set of abbreviations to speed up insertion of LaTeX math constructs. Typing a short abbreviation followed by pressing Tab give very rapid access to frequently used LaTeX commands and environment templates. For example, typing / followed by Tab will expand to \frac{}{} and position the cursor correctly inside the first pair of braces. Another Tab will move you from the first argument to the second.

The main goal is to create an easy-to-learn and scalable set of abbreviations. The system is designed mainly to support composing of LaTeX documents, but can be useful for writing in any format accepting LaTeX math input, like Markdown, reStructuredText, AsciiDoc, etc.

An overview of the defined abbreviations is available in Markdown format for reference.

Note: This is still pretty much work-in-progress and I expect some abbreviations will change in the future.

General Principles

The following general rules hold in order to enter LaTeX math commands and environments:

  • Many mathematical symbols and operators are obtained by "natural" key combinations. For instance, +- yields \pm, << yields \ll, o+ yields \oplus, xx yields \times, / yields \frac{}{}, etc.

  • Greek letters can be obtained as "variants" of Latin letters using the . prefix. For instance, .p yields \pi. Variants are obtained by doubling up appropriate Latin letters. For instance, .e yields \epsilon, while .ee yields \varepsilon.

  • Putting accents on mathematical characters uses key combinations with the quote character ' as a prefix: For instance, '~ yields \tilde{}.

  • The prefix ! is used for negation: For instance, != yields \neq.

  • Environment templates can be entered using the : prefix: For instance, :eqn expands to

    \begin{equation}
      |
    \end{equation}
  • Font and style commands can be entered using the & prefix: For instance, &fr expands to \mathfrac{}.

  • The @ prefix is reserved for user-defined building blocks and expressions: For example, @ddt can be defined to yield the expression

    \frac{\partial}{\partial t}
  • Some commands have aliases for semantic purposes or easy access on various country-specific keyboard layouts.

Implementation

The set of abbreviations is implemented using YASnippet template system for GNU Emacs. YASnippet allows you to type an abbreviation and automatically expand it into function templates. For information about installation of YASnippet and its snippets, i.e., templates, please consult corresponding GitHub page and repository. Following are some notes on installation and setup specific to snippets provided here.

Installation

  1. If not already done, load the YASnippet package and set the yas-snippet-dirs variable in your Emacs config file:

    (require 'yasnippet)
    (setq yas-snippet-dirs '("~/.emacs.d/snippets"))
    (yas-global-mode 1)
  2. Copy the content of the yasnippets folder to one of the directories specified in the yas-snippet-dirs variable (in this case ~/.emacs.d/snippets).

Configuration

The snippets provided here are defined for the LaTeX major mode. If you want to use them in other modes, like Markdown mode or Org mode, you need to add latex-mode to the mode list of the corresponding .yas-parents file as described in the YASnippets documentation.

Most snippets, except for math environments that are supposed to be used to initiate math mode, have the condition field set to (yas-texmathp). The latter is intended to control expansion depending on the local context and can be defined as

(defun yas-texmathp () (require 'texmathp) (texmathp))

This example uses the function texmathp defined in AUCTeX (autoloaded from texmathp.el), which evaluates to t if the cursor is in math expression and to nil otherwise. The function is aware of all environments that AUCTeX knows of, and you can add more using the custom option texmathp-tex-commands.

latex-math-input's People

Contributors

saf-dmitry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

latex-math-input's Issues

About usage in org-mode and nested directory

Hi,
I am looking for snippet for math in org-mode, great job.

Here are some questions, hope you can help:

  1. It seems yasnippet does no support nested directory, but in this repo the snippet are in nested directory, so how to use it?
  2. Any idea how to use it in org-mode, it seems there is an texmathp condition in all snippets, which is not compatible with org-mode

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.