;;; org-entities.el --- Support for special entities in Org-mode

;; Copyright (C) 2010-2012 Free Software Foundation, Inc.

;; Author: Carsten Dominik <carsten at orgmode dot org>,
;;         Ulf Stegemann <ulf at zeitform dot de>
;; Keywords: outlines, calendar, wp
;; Homepage: http://orgmode.org
;;
;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:

;;; Code:

(require 'org-macs)

(declare-function org-table-align "org-table" ())

(eval-when-compile
  (require 'cl))

(defgroup org-entities nil
  "Options concerning entities in Org-mode."
  :tag "Org Entities"
  :group 'org)

(defcustom org-entities-ascii-explanatory nil
  "Non-nil means replace special entities in ASCII.
For example, this will replace \"\\nsup\" with \"[not a superset of]\"
in backends where the corresponding character is not available."
  :group 'org-entities
  :version "24.1"
  :type 'boolean)

(defcustom org-entities-user nil
  "User-defined entities used in Org-mode to produce special characters.
Each entry in this list is a list of strings.  It associates the name
of the entity that can be inserted into an Org file as \\name with the
appropriate replacements for the different export backends.  The order
of the fields is the following

name                 As a string, without the leading backslash
LaTeX replacement    In ready LaTeX, no further processing will take place
LaTeX mathp          A Boolean, either t or nil.  t if this entity needs
                     to be in math mode.
HTML replacement     In ready HTML, no further processing will take place.
                     Usually this will be an &...; entity.
ASCII replacement    Plain ASCII, no extensions.  Symbols that cannot be
                     represented will be left as they are, but see the.
                     variable `org-entities-ascii-explanatory'.
Latin1 replacement   Use the special characters available in latin1.
utf-8 replacement    Use the special characters available in utf-8.

If you define new entities here that require specific LaTeX packages to be
loaded, add these packages to `org-export-latex-packages-alist'."
  :group 'org-entities
  :version "24.1"
  :type '(repeat
	  (list
	   (string :tag "name  ")
	   (string :tag "LaTeX ")
	   (boolean :tag "Require LaTeX math?")
	   (string :tag "HTML  ")
	   (string :tag "ASCII ")
	   (string :tag "Latin1")
	   (string :tag "utf-8 "))))

(defconst org-entities
  '(
    "* Letters"
    "** Latin"
    ("Agrave" "\\`{A}" nil "&Agrave;" "A" "√Ä" "√Ä")
    ("agrave" "\\`{a}" nil "&agrave;" "a" "√†" "√†")
    ("Aacute" "\\'{A}" nil "&Aacute;" "A" "√Å" "√Å")
    ("aacute" "\\'{a}" nil "&aacute;" "a" "√°" "√°")
    ("Acirc" "\\^{A}" nil "&Acirc;" "A" "√Ç" "√Ç")
    ("acirc" "\\^{a}" nil "&acirc;" "a" "√¢" "√¢")
    ("Atilde" "\\~{A}" nil "&Atilde;" "A" "√É" "√É")
    ("atilde" "\\~{a}" nil "&atilde;" "a" "√£" "√£")
    ("Auml" "\\\"{A}" nil "&Auml;" "Ae" "√Ñ" "√Ñ")
    ("auml" "\\\"{a}" nil "&auml;" "ae" "√§" "√§")
    ("Aring" "\\AA{}" nil "&Aring;" "A" "√Ö" "√Ö")
    ("AA" "\\AA{}" nil "&Aring;" "A" "√Ö" "√Ö")
    ("aring" "\\aa{}" nil "&aring;" "a" "√•" "√•")
    ("AElig" "\\AE{}" nil "&AElig;" "AE" "√Ü" "√Ü")
    ("aelig" "\\ae{}" nil "&aelig;" "ae" "√¶" "√¶")
    ("Ccedil" "\\c{C}" nil "&Ccedil;" "C" "√á" "√á")
    ("ccedil" "\\c{c}" nil "&ccedil;" "c" "√ß" "√ß")
    ("Egrave" "\\`{E}" nil "&Egrave;" "E" "√à" "√à")
    ("egrave" "\\`{e}" nil "&egrave;" "e" "√®" "√®")
    ("Eacute" "\\'{E}" nil "&Eacute;" "E" "√â" "√â")
    ("eacute" "\\'{e}" nil "&eacute;" "e" "√©" "√©")
    ("Ecirc" "\\^{E}" nil "&Ecirc;" "E" "√ä" "√ä")
    ("ecirc" "\\^{e}" nil "&ecirc;" "e" "√™" "√™")
    ("Euml" "\\\"{E}" nil "&Euml;" "E" "√ã" "√ã")
    ("euml" "\\\"{e}" nil "&euml;" "e" "√´" "√´")
    ("Igrave" "\\`{I}" nil "&Igrave;" "I" "√å" "√å")
    ("igrave" "\\`{i}" nil "&igrave;" "i" "√¨" "√¨")
    ("Iacute" "\\'{I}" nil "&Iacute;" "I" "√ç" "√ç")
    ("iacute" "\\'{i}" nil "&iacute;" "i" "√≠" "√≠")
    ("Icirc" "\\^{I}" nil "&Icirc;" "I" "√é" "√é")
    ("icirc" "\\^{i}" nil "&icirc;" "i" "√Æ" "√Æ")
    ("Iuml" "\\\"{I}" nil "&Iuml;" "I" "√è" "√è")
    ("iuml" "\\\"{i}" nil "&iuml;" "i" "√Ø" "√Ø")
    ("Ntilde" "\\~{N}" nil "&Ntilde;" "N" "√ë" "√ë")
    ("ntilde" "\\~{n}" nil "&ntilde;" "n" "√±" "√±")
    ("Ograve" "\\`{O}" nil "&Ograve;" "O" "√í" "√í")
    ("ograve" "\\`{o}" nil "&ograve;" "o" "√≤" "√≤")
    ("Oacute" "\\'{O}" nil "&Oacute;" "O" "√ì" "√ì")
    ("oacute" "\\'{o}" nil "&oacute;" "o" "√≥" "√≥")
    ("Ocirc" "\\^{O}" nil "&Ocirc;" "O" "√î" "√î")
    ("ocirc" "\\^{o}" nil "&ocirc;" "o" "√¥" "√¥")
    ("Otilde" "\\~{O}" nil "&Otilde;" "O" "√ï" "√ï")
    ("otilde" "\\~{o}" nil "&otilde;" "o" "√µ" "√µ")
    ("Ouml" "\\\"{O}" nil "&Ouml;" "Oe" "√ñ" "√ñ")
    ("ouml" "\\\"{o}" nil "&ouml;" "oe" "√∂" "√∂")
    ("Oslash" "\\O" nil "&Oslash;" "O" "√ò" "√ò")
    ("oslash" "\\o{}" nil "&oslash;" "o" "√∏" "√∏")
    ("OElig" "\\OE{}" nil "&OElig;" "OE" "OE" "≈í")
    ("oelig" "\\oe{}" nil "&oelig;" "oe" "oe" "≈ì")
    ("Scaron" "\\v{S}" nil "&Scaron;" "S" "S" "≈†")
    ("scaron" "\\v{s}" nil "&scaron;" "s" "s" "≈°")
    ("szlig" "\\ss{}" nil "&szlig;" "ss" "√ü" "√ü")
    ("Ugrave" "\\`{U}" nil "&Ugrave;" "U" "√ô" "√ô")
    ("ugrave" "\\`{u}" nil "&ugrave;" "u" "√π" "√π")
    ("Uacute" "\\'{U}" nil "&Uacute;" "U" "√ö" "√ö")
    ("uacute" "\\'{u}" nil "&uacute;" "u" "√∫" "√∫")
    ("Ucirc" "\\^{U}" nil "&Ucirc;" "U" "√õ" "√õ")
    ("ucirc" "\\^{u}" nil "&ucirc;" "u" "√ª" "√ª")
    ("Uuml" "\\\"{U}" nil "&Uuml;" "Ue" "√ú" "√ú")
    ("uuml" "\\\"{u}" nil "&uuml;" "ue" "√º" "√º")
    ("Yacute" "\\'{Y}" nil "&Yacute;" "Y" "√ù" "√ù")
    ("yacute" "\\'{y}" nil "&yacute;" "y" "√Ω" "√Ω")
    ("Yuml" "\\\"{Y}" nil "&Yuml;" "Y" "Y" "≈∏")
    ("yuml" "\\\"{y}" nil "&yuml;" "y" "√ø" "√ø")

    "** Latin (special face)"
    ("fnof" "\\textit{f}" nil "&fnof;" "f" "f" "∆í")
    ("real" "\\Re" t "&real;" "R" "R" "‚Ñú")
    ("image" "\\Im" t "&image;" "I" "I" "‚Ñë")
    ("weierp" "\\wp" t "&weierp;" "P" "P" "‚Ñò")

    "** Greek"
    ("Alpha" "A" nil "&Alpha;" "Alpha" "Alpha" "Œë")
    ("alpha" "\\alpha" t "&alpha;" "alpha" "alpha" "Œ±")
    ("Beta" "B" nil "&Beta;" "Beta" "Beta" "Œí")
    ("beta" "\\beta" t "&beta;" "beta" "beta" "Œ≤")
    ("Gamma" "\\Gamma" t "&Gamma;" "Gamma" "Gamma" "Œì")
    ("gamma" "\\gamma" t "&gamma;" "gamma" "gamma" "Œ≥")
    ("Delta" "\\Delta" t "&Delta;" "Delta" "Gamma" "Œî")
    ("delta" "\\delta" t "&delta;" "delta" "delta" "Œ¥")
    ("Epsilon" "E" nil "&Epsilon;" "Epsilon" "Epsilon" "Œï")
    ("epsilon" "\\epsilon" t "&epsilon;" "epsilon" "epsilon" "Œµ")
    ("varepsilon" "\\varepsilon" t "&epsilon;" "varepsilon" "varepsilon" "Œµ")
    ("Zeta" "Z" nil "&Zeta;" "Zeta" "Zeta" "Œñ")
    ("zeta" "\\zeta" t "&zeta;" "zeta" "zeta" "Œ∂")
    ("Eta" "H" nil "&Eta;" "Eta" "Eta" "Œó")
    ("eta" "\\eta" t "&eta;" "eta" "eta" "Œ∑")
    ("Theta" "\\Theta" t "&Theta;" "Theta" "Theta" "Œò")
    ("theta" "\\theta" t "&theta;" "theta" "theta" "Œ∏")
    ("thetasym" "\\vartheta" t "&thetasym;" "theta" "theta" "œë")
    ("vartheta" "\\vartheta" t "&thetasym;" "theta" "theta" "œë")
    ("Iota" "I" nil "&Iota;" "Iota" "Iota" "Œô")
    ("iota" "\\iota" t "&iota;" "iota" "iota" "Œπ")
    ("Kappa" "K" nil "&Kappa;" "Kappa" "Kappa" "Œö")
    ("kappa" "\\kappa" t "&kappa;" "kappa" "kappa" "Œ∫")
    ("Lambda" "\\Lambda" t "&Lambda;" "Lambda" "Lambda" "Œõ")
    ("lambda" "\\lambda" t "&lambda;" "lambda" "lambda" "Œª")
    ("Mu" "M" nil "&Mu;" "Mu" "Mu" "Œú")
    ("mu" "\\mu" t "&mu;" "mu" "mu" "Œº")
    ("nu" "\\nu" t "&nu;" "nu" "nu" "ŒΩ")
    ("Nu" "N" nil "&Nu;" "Nu" "Nu" "Œù")
    ("Xi" "\\Xi" t "&Xi;" "Xi" "Xi" "Œû")
    ("xi" "\\xi" t "&xi;" "xi" "xi" "Œæ")
    ("Omicron" "O" nil "&Omicron;" "Omicron" "Omicron" "Œü")
    ("omicron" "\\textit{o}" nil "&omicron;" "omicron" "omicron" "Œø")
    ("Pi" "\\Pi" t "&Pi;" "Pi" "Pi" "Œ†")
    ("pi" "\\pi" t "&pi;" "pi" "pi" "œÄ")
    ("Rho" "P" nil "&Rho;" "Rho" "Rho" "Œ°")
    ("rho" "\\rho" t "&rho;" "rho" "rho" "œÅ")
    ("Sigma" "\\Sigma" t "&Sigma;" "Sigma" "Sigma" "Œ£")
    ("sigma" "\\sigma" t "&sigma;" "sigma" "sigma" "œÉ")
    ("sigmaf" "\\varsigma" t "&sigmaf;" "sigmaf" "sigmaf" "œÇ")
    ("varsigma" "\\varsigma" t "&sigmaf;" "varsigma" "varsigma" "œÇ")
    ("Tau" "T" nil "&Tau;" "Tau" "Tau" "Œ§")
    ("Upsilon" "\\Upsilon" t "&Upsilon;" "Upsilon" "Upsilon" "Œ•")
    ("upsih" "\\Upsilon" t "&upsih;" "upsilon" "upsilon" "œí")
    ("upsilon" "\\upsilon" t "&upsilon;" "upsilon" "upsilon" "œÖ")
    ("Phi" "\\Phi" t "&Phi;" "Phi" "Phi" "Œ¶")
    ("phi" "\\phi" t "&phi;" "phi" "phi" "œÜ")
    ("Chi" "X" nil "&Chi;" "Chi" "Chi" "Œß")
    ("chi" "\\chi" t "&chi;" "chi" "chi" "œá")
    ("acutex" "\\acute x" t "&acute;x" "'x" "'x" "ùë•ÃÅ")
    ("Psi" "\\Psi" t "&Psi;" "Psi" "Psi" "Œ®")
    ("psi" "\\psi" t "&psi;" "psi" "psi" "œà")
    ("tau" "\\tau" t "&tau;" "tau" "tau" "œÑ")
    ("Omega" "\\Omega" t "&Omega;" "Omega" "Omega" "Œ©")
    ("omega" "\\omega" t "&omega;" "omega" "omega" "œâ")
    ("piv" "\\varpi" t "&piv;" "omega-pi" "omega-pi" "œñ")
    ("partial" "\\partial" t "&part;" "[partial differential]" "[partial differential]" "‚àÇ")

    "** Hebrew"
    ("alefsym" "\\aleph" t "&alefsym;" "aleph" "aleph" "‚Ñµ")

    "** Dead languages"
    ("ETH" "\\DH{}" nil "&ETH;" "D" "√ê" "√ê")
    ("eth" "\\dh{}" nil "&eth;" "dh" "√∞" "√∞")
    ("THORN" "\\TH{}" nil "&THORN;" "TH" "√û" "√û")
    ("thorn" "\\th{}" nil "&thorn;" "th" "√æ" "√æ")

    "* Punctuation"
    "** Dots and Marks"
    ("dots" "\\dots{}" nil "&hellip;" "..." "..." "‚Ä¶")
    ("hellip" "\\dots{}" nil "&hellip;" "..." "..." "‚Ä¶")
    ("middot" "\\textperiodcentered{}" nil "&middot;" "." "¬∑" "¬∑")
    ("iexcl" "!`" nil "&iexcl;" "!" "¬°" "¬°")
    ("iquest" "?`" nil "&iquest;" "?" "¬ø" "¬ø")

    "** Dash-like"
    ("shy" "\\-" nil "&shy;" "" "" "")
    ("ndash" "--" nil "&ndash;" "-" "-" "‚Äì")
    ("mdash" "---" nil "&mdash;" "--" "--" "‚Äî")

    "** Quotations"
    ("quot" "\\textquotedbl{}" nil "&quot;" "\"" "\"" "\"")
    ("acute" "\\textasciiacute{}" nil "&acute;" "'" "¬¥" "¬¥")
    ("ldquo" "\\textquotedblleft{}" nil "&ldquo;" "\"" "\"" "‚Äú")
    ("rdquo" "\\textquotedblright{}" nil "&rdquo;" "\"" "\"" "‚Äù")
    ("bdquo" "\\quotedblbase{}" nil "&bdquo;" "\"" "\"" "‚Äû")
    ("lsquo" "\\textquoteleft{}" nil "&lsquo;" "`" "`" "‚Äò")
    ("rsquo" "\\textquoteright{}" nil "&rsquo;" "'" "'" "‚Äô")
    ("sbquo" "\\quotesinglbase{}" nil "&sbquo;" "," "," "‚Äö")
    ("laquo" "\\guillemotleft{}" nil "&laquo;" "<<" "¬´" "¬´")
    ("raquo" "\\guillemotright{}" nil "&raquo;" ">>" "¬ª" "¬ª")
    ("lsaquo" "\\guilsinglleft{}" nil "&lsaquo;" "<" "<" "‚Äπ")
    ("rsaquo" "\\guilsinglright{}" nil "&rsaquo;" ">" ">" "‚Ä∫")

    "* Other"
    "** Misc. (often used)"
    ("circ" "\\^{}" nil "&circ;" "^" "^" "ÀÜ")
    ("vert" "\\vert{}" t "&#124;" "|" "|" "|")
    ("brvbar" "\\textbrokenbar{}" nil "&brvbar;" "|" "¬¶" "¬¶")
    ("sect" "\\S" nil "&sect;" "paragraph" "¬ß" "¬ß")
    ("amp" "\\&" nil "&amp;" "&" "&" "&")
    ("lt" "\\textless{}" nil "&lt;" "<" "<" "<")
    ("gt" "\\textgreater{}" nil "&gt;" ">" ">" ">")
    ("tilde" "\\~{}" nil "&tilde;" "~" "~" "~")
    ("slash" "/" nil "/" "/" "/" "/")
    ("plus" "+" nil "+" "+" "+" "+")
    ("under" "\\_" nil "_" "_" "_" "_")
    ("equal" "=" nil "=" "=" "=" "=")
    ("asciicirc" "\\textasciicircum{}" nil "^" "^" "^" "^")
    ("dagger" "\\textdagger{}" nil "&dagger;" "[dagger]" "[dagger]" "‚Ä†")
    ("Dagger" "\\textdaggerdbl{}" nil "&Dagger;" "[doubledagger]" "[doubledagger]" "‚Ä°")

    "** Whitespace"
    ("nbsp" "~" nil "&nbsp;" " " " " " ")
    ("ensp" "\\hspace*{.5em}" nil "&ensp;" " " " " "‚ÄÇ")
    ("emsp" "\\hspace*{1em}" nil "&emsp;" " " " " "‚ÄÉ")
    ("thinsp" "\\hspace*{.2em}" nil "&thinsp;" " " " " "‚Äâ")

    "** Currency"
    ("curren" "\\textcurrency{}" nil "&curren;" "curr." "¬§" "¬§")
    ("cent" "\\textcent{}" nil "&cent;" "cent" "¬¢" "¬¢")
    ("pound" "\\pounds{}" nil "&pound;" "pound" "¬£" "¬£")
    ("yen" "\\textyen{}" nil "&yen;" "yen" "¬•" "¬•")
    ("euro" "\\texteuro{}" nil "&euro;" "EUR" "EUR" "‚Ç¨")
    ("EUR" "\\EUR{}" nil "&euro;" "EUR" "EUR" "‚Ç¨")
    ("EURdig" "\\EURdig{}" nil "&euro;" "EUR" "EUR" "‚Ç¨")
    ("EURhv" "\\EURhv{}" nil "&euro;" "EUR" "EUR" "‚Ç¨")
    ("EURcr" "\\EURcr{}" nil "&euro;" "EUR" "EUR" "‚Ç¨")
    ("EURtm" "\\EURtm{}" nil "&euro;" "EUR" "EUR" "‚Ç¨")

    "** Property Marks"
    ("copy" "\\textcopyright{}" nil "&copy;" "(c)" "¬©" "¬©")
    ("reg" "\\textregistered{}" nil "&reg;" "(r)" "¬Æ" "¬Æ")
    ("trade" "\\texttrademark{}" nil "&trade;" "TM" "TM" "‚Ñ¢")

    "** Science et al."
    ("minus" "\\minus" t "&minus;" "-" "-" "‚àí")
    ("pm" "\\textpm{}" nil "&plusmn;" "+-" "¬±" "¬±")
    ("plusmn" "\\textpm{}" nil "&plusmn;" "+-" "¬±" "¬±")
    ("times" "\\texttimes{}" nil "&times;" "*" "√ó" "√ó")
    ("frasl" "/" nil "&frasl;" "/" "/" "‚ÅÑ")
    ("div" "\\textdiv{}" nil "&divide;" "/" "√∑" "√∑")
    ("frac12" "\\textonehalf{}" nil "&frac12;" "1/2" "¬Ω" "¬Ω")
    ("frac14" "\\textonequarter{}" nil "&frac14;" "1/4" "¬º" "¬º")
    ("frac34" "\\textthreequarters{}" nil "&frac34;" "3/4" "¬æ" "¬æ")
    ("permil" "\\textperthousand{}" nil "&permil;" "per thousand" "per thousand" "‚Ä∞")
    ("sup1" "\\textonesuperior{}" nil "&sup1;" "^1" "¬π" "¬π")
    ("sup2" "\\texttwosuperior{}" nil "&sup2;" "^2" "¬≤" "¬≤")
    ("sup3" "\\textthreesuperior{}" nil "&sup3;" "^3" "¬≥" "¬≥")
    ("radic" "\\sqrt{\\,}" t "&radic;" "[square root]" "[square root]" "‚àö")
    ("sum" "\\sum" t "&sum;" "[sum]" "[sum]" "‚àë")
    ("prod" "\\prod" t "&prod;" "[product]" "[n-ary product]" "‚àè")
    ("micro" "\\textmu{}" nil "&micro;" "micro" "¬µ" "¬µ")
    ("macr" "\\textasciimacron{}" nil "&macr;" "[macron]" "¬Ø" "¬Ø")
    ("deg" "\\textdegree{}" nil "&deg;" "degree" "¬∞" "¬∞")
    ("prime" "\\prime" t "&prime;" "'" "'" "‚Ä≤")
    ("Prime" "\\prime{}\\prime" t "&Prime;" "''" "''" "‚Ä≥")
    ("infin" "\\propto" t "&infin;" "[infinity]" "[infinity]" "‚àû")
    ("infty" "\\infty" t "&infin;" "[infinity]" "[infinity]" "‚àû")
    ("prop" "\\propto" t "&prop;" "[proportional to]" "[proportional to]" "‚àù")
    ("proptp" "\\propto" t "&prop;" "[proportional to]" "[proportional to]" "‚àù")
    ("not" "\\textlnot{}" nil "&not;" "[angled dash]" "¬¨" "¬¨")
    ("land" "\\land" t "&and;" "[logical and]" "[logical and]" "‚àß")
    ("wedge" "\\wedge" t "&and;" "[logical and]" "[logical and]" "‚àß")
    ("lor" "\\lor" t "&or;" "[logical or]" "[logical or]" "‚à®")
    ("vee" "\\vee" t "&or;" "[logical or]" "[logical or]" "‚à®")
    ("cap" "\\cap" t "&cap;" "[intersection]" "[intersection]" "‚à©")
    ("cup" "\\cup" t "&cup;" "[union]" "[union]" "‚à™")
    ("int" "\\int" t "&int;" "[integral]" "[integral]" "‚à´")
    ("there4" "\\therefore" t "&there4;" "[therefore]" "[therefore]" "‚à¥")
    ("sim" "\\sim" t "&sim;" "~" "~" "‚àº")
    ("cong" "\\cong" t "&cong;" "[approx. equal to]" "[approx. equal to]" "‚âÖ")
    ("simeq" "\\simeq" t "&cong;"  "[approx. equal to]" "[approx. equal to]" "‚âÖ")
    ("asymp" "\\asymp" t "&asymp;" "[almost equal to]" "[almost equal to]" "‚âà")
    ("approx" "\\approx" t "&asymp;" "[almost equal to]" "[almost equal to]" "‚âà")
    ("ne" "\\ne" t "&ne;" "[not equal to]" "[not equal to]" "‚â†")
    ("neq" "\\neq" t "&ne;" "[not equal to]" "[not equal to]" "‚â†")
    ("equiv" "\\equiv" t "&equiv;" "[identical to]" "[identical to]" "‚â°")
    ("le" "\\le" t "&le;" "<=" "<=" "‚â§")
    ("ge" "\\ge" t "&ge;" ">=" ">=" "‚â•")
    ("sub" "\\subset" t "&sub;" "[subset of]" "[subset of]" "‚äÇ")
    ("subset" "\\subset" t "&sub;" "[subset of]" "[subset of]" "‚äÇ")
    ("sup" "\\supset" t "&sup;" "[superset of]" "[superset of]" "‚äÉ")
    ("supset" "\\supset" t "&sup;" "[superset of]" "[superset of]" "‚äÉ")
    ("nsub" "\\not\\subset" t "&nsub;" "[not a subset of]" "[not a subset of" "‚äÑ")
    ("sube" "\\subseteq" t "&sube;" "[subset of or equal to]" "[subset of or equal to]" "‚äÜ")
    ("nsup" "\\not\\supset" t "&nsup;" "[not a superset of]" "[not a superset of]" "‚äÖ")
    ("supe" "\\supseteq" t "&supe;" "[superset of or equal to]" "[superset of or equal to]" "‚äá")
    ("forall" "\\forall" t "&forall;" "[for all]" "[for all]" "‚àÄ")
    ("exist" "\\exists" t "&exist;" "[there exists]" "[there exists]" "‚àÉ")
    ("exists" "\\exists" t "&exist;" "[there exists]" "[there exists]" "‚àÉ")
    ("empty" "\\empty" t "&empty;" "[empty set]" "[empty set]" "‚àÖ")
    ("emptyset" "\\emptyset" t "&empty;" "[empty set]" "[empty set]" "‚àÖ")
    ("isin" "\\in" t "&isin;" "[element of]" "[element of]" "‚àà")
    ("in" "\\in" t "&isin;" "[element of]" "[element of]" "‚àà")
    ("notin" "\\notin" t "&notin;" "[not an element of]" "[not an element of]" "‚àâ")
    ("ni" "\\ni" t "&ni;" "[contains as member]" "[contains as member]" "‚àã")
    ("nabla" "\\nabla" t "&nabla;" "[nabla]" "[nabla]" "‚àá")
    ("ang" "\\angle" t "&ang;" "[angle]" "[angle]" "‚à†")
    ("angle" "\\angle" t "&ang;" "[angle]" "[angle]" "‚à†")
    ("perp" "\\perp" t "&perp;" "[up tack]" "[up tack]" "‚ä•")
    ("sdot" "\\cdot" t "&sdot;" "[dot]" "[dot]" "‚ãÖ")
    ("cdot" "\\cdot" t "&sdot;" "[dot]" "[dot]" "‚ãÖ")
    ("lceil" "\\lceil" t "&lceil;" "[left ceiling]" "[left ceiling]" "‚åà")
    ("rceil" "\\rceil" t "&rceil;" "[right ceiling]" "[right ceiling]" "‚åâ")
    ("lfloor" "\\lfloor" t "&lfloor;" "[left floor]" "[left floor]" "‚åä")
    ("rfloor" "\\rfloor" t "&rfloor;" "[right floor]" "[right floor]" "‚åã")
    ("lang" "\\langle" t "&lang;" "<" "<" "‚ü®")
    ("rang" "\\rangle" t "&rang;" ">" ">" "‚ü©")

    "** Arrows"
    ("larr" "\\leftarrow" t "&larr;" "<-" "<-" "‚Üê")
    ("leftarrow" "\\leftarrow" t "&larr;"  "<-" "<-" "‚Üê")
    ("gets" "\\gets" t "&larr;"  "<-" "<-" "‚Üê")
    ("lArr" "\\Leftarrow" t "&lArr;" "<=" "<=" "‚áê")
    ("Leftarrow" "\\Leftarrow" t "&lArr;" "<=" "<=" "‚áê")
    ("uarr" "\\uparrow" t "&uarr;" "[uparrow]" "[uparrow]" "‚Üë")
    ("uparrow" "\\uparrow" t "&uarr;" "[uparrow]" "[uparrow]" "‚Üë")
    ("uArr" "\\Uparrow" t "&uArr;" "[dbluparrow]" "[dbluparrow]" "‚áë")
    ("Uparrow" "\\Uparrow" t "&uArr;" "[dbluparrow]" "[dbluparrow]" "‚áë")
    ("rarr" "\\rightarrow" t "&rarr;" "->" "->" "‚Üí")
    ("to" "\\to" t "&rarr;" "->" "->" "‚Üí")
    ("rightarrow" "\\rightarrow" t "&rarr;"  "->" "->" "‚Üí")
    ("rArr" "\\Rightarrow" t "&rArr;" "=>" "=>" "‚áí")
    ("Rightarrow" "\\Rightarrow" t "&rArr;" "=>" "=>" "‚áí")
    ("darr" "\\downarrow" t "&darr;" "[downarrow]" "[downarrow]" "‚Üì")
    ("downarrow" "\\downarrow" t "&darr;" "[downarrow]" "[downarrow]" "‚Üì")
    ("dArr" "\\Downarrow" t "&dArr;" "[dbldownarrow]" "[dbldownarrow]" "‚áì")
    ("Downarrow" "\\Downarrow" t "&dArr;" "[dbldownarrow]" "[dbldownarrow]" "‚áì")
    ("harr" "\\leftrightarrow" t "&harr;" "<->" "<->" "‚Üî")
    ("leftrightarrow" "\\leftrightarrow" t "&harr;"  "<->" "<->" "‚Üî")
    ("hArr" "\\Leftrightarrow" t "&hArr;" "<=>" "<=>" "‚áî")
    ("Leftrightarrow" "\\Leftrightarrow" t "&hArr;" "<=>" "<=>" "‚áî")
    ("crarr" "\\hookleftarrow" t "&crarr;" "<-'" "<-'" "‚Üµ")
    ("hookleftarrow" "\\hookleftarrow" t "&crarr;"  "<-'" "<-'" "‚Üµ")

    "** Function names"
    ("arccos" "\\arccos" t "arccos" "arccos" "arccos" "arccos")
    ("arcsin" "\\arcsin" t "arcsin" "arcsin" "arcsin" "arcsin")
    ("arctan" "\\arctan" t "arctan" "arctan" "arctan" "arctan")
    ("arg" "\\arg" t "arg" "arg" "arg" "arg")
    ("cos" "\\cos" t "cos" "cos" "cos" "cos")
    ("cosh" "\\cosh" t "cosh" "cosh" "cosh" "cosh")
    ("cot" "\\cot" t "cot" "cot" "cot" "cot")
    ("coth" "\\coth" t "coth" "coth" "coth" "coth")
    ("csc" "\\csc" t "csc" "csc" "csc" "csc")
    ("deg" "\\deg" t "&deg;" "deg" "deg" "deg")
    ("det" "\\det" t "det" "det" "det" "det")
    ("dim" "\\dim" t "dim" "dim" "dim" "dim")
    ("exp" "\\exp" t "exp" "exp" "exp" "exp")
    ("gcd" "\\gcd" t "gcd" "gcd" "gcd" "gcd")
    ("hom" "\\hom" t "hom" "hom" "hom" "hom")
    ("inf" "\\inf" t "inf" "inf" "inf" "inf")
    ("ker" "\\ker" t "ker" "ker" "ker" "ker")
    ("lg" "\\lg" t "lg" "lg" "lg" "lg")
    ("lim" "\\lim" t "lim" "lim" "lim" "lim")
    ("liminf" "\\liminf" t "liminf" "liminf" "liminf" "liminf")
    ("limsup" "\\limsup" t "limsup" "limsup" "limsup" "limsup")
    ("ln" "\\ln" t "ln" "ln" "ln" "ln")
    ("log" "\\log" t "log" "log" "log" "log")
    ("max" "\\max" t "max" "max" "max" "max")
    ("min" "\\min" t "min" "min" "min" "min")
    ("Pr" "\\Pr" t "Pr" "Pr" "Pr" "Pr")
    ("sec" "\\sec" t "sec" "sec" "sec" "sec")
    ("sin" "\\sin" t "sin" "sin" "sin" "sin")
    ("sinh" "\\sinh" t "sinh" "sinh" "sinh" "sinh")
    ("sup" "\\sup" t "&sup;" "sup" "sup" "sup")
    ("tan" "\\tan" t "tan" "tan" "tan" "tan")
    ("tanh" "\\tanh" t "tanh" "tanh" "tanh" "tanh")

    "** Signs & Symbols"
    ("bull" "\\textbullet{}" nil "&bull;" "*" "*" "‚Ä¢")
    ("bullet" "\\textbullet{}" nil "&bull;" "*" "*" "‚Ä¢")
    ("star" "\\star" t "*" "*" "*" "‚ãÜ")
    ("lowast" "\\ast" t "&lowast;" "*" "*" "‚àó")
    ("ast" "\\ast" t "&lowast;" "*" "*" "*")
    ("odot" "\\odot" t "o" "[circled dot]" "[circled dot]" " ò")
    ("oplus" "\\oplus" t "&oplus;" "[circled plus]" "[circled plus]" "‚äï")
    ("otimes" "\\otimes" t "&otimes;" "[circled times]" "[circled times]" "‚äó")
    ("checkmark" "\\checkmark" t "&#10003;" "[checkmark]" "[checkmark]" "‚úì")

    "** Miscellaneous (seldom used)"
    ("para" "\\P{}" nil "&para;" "[pilcrow]" "¬∂" "¬∂")
    ("ordf" "\\textordfeminine{}" nil "&ordf;" "_a_" "¬™" "¬™")
    ("ordm" "\\textordmasculine{}" nil "&ordm;" "_o_" "¬∫" "¬∫")
    ("cedil" "\\c{}" nil "&cedil;" "[cedilla]" "¬∏" "¬∏")
    ("oline" "\\overline{~}" t "&oline;" "[overline]" "¬Ø" "‚Äæ")
    ("uml" "\\textasciidieresis{}" nil "&uml;" "[diaeresis]" "¬®" "¬®")
    ("zwnj" "\\/{}" nil "&zwnj;" "" "" "‚Äå")
    ("zwj" "" nil "&zwj;" "" "" "‚Äç")
    ("lrm" "" nil "&lrm;" "" "" "‚Äé")
    ("rlm" "" nil "&rlm;" "" "" "‚Äè")

    "** Smilies"
    ("smile" "\\smile" t "&#9786;" ":-)" ":-)" "‚å£")
    ("smiley" "\\smiley{}" nil "&#9786;" ":-)" ":-)" "‚ò∫")
    ("blacksmile" "\\blacksmiley{}" nil "&#9787;" ":-)" ":-)" "‚òª")
    ("sad" "\\frownie{}" nil "&#9785;" ":-(" ":-(" "‚òπ")

    "** Suits"
    ("clubs" "\\clubsuit" t "&clubs;" "[clubs]" "[clubs]" "‚ô£")
    ("clubsuit" "\\clubsuit" t "&clubs;" "[clubs]" "[clubs]" "‚ô£")
    ("spades" "\\spadesuit" t "&spades;" "[spades]" "[spades]" "‚ô†")
    ("spadesuit" "\\spadesuit" t "&spades;" "[spades]" "[spades]" "‚ô†")
    ("hearts" "\\heartsuit" t "&hearts;" "[hearts]" "[hearts]" "‚ô•")
    ("heartsuit" "\\heartsuit" t "&heartsuit;" "[hearts]" "[hearts]" "‚ô•")
    ("diams" "\\diamondsuit" t "&diams;" "[diamonds]" "[diamonds]" "‚ô¶")
    ("diamondsuit" "\\diamondsuit" t "&diams;" "[diamonds]" "[diamonds]" "‚ô¶")
    ("Diamond" "\\diamond" t "&diamond;" "[diamond]" "[diamond]" "‚ãÑ")
    ("loz" "\\diamond" t "&loz;" "[lozenge]" "[lozenge]" "‚óä")
    )
  "Default entities used in Org-mode to produce special characters.
For details see `org-entities-user'.")

(defsubst org-entity-get (name)
  "Get the proper association for NAME from the entity lists.
This first checks the user list, then the built-in list."
  (or (assoc name org-entities-user)
      (assoc name org-entities)))

(defun org-entity-get-representation (name kind)
  "Get the correct representation of entity NAME for export type KIND.
Kind can be any of `latex', `html', `ascii', `latin1', or `utf8'."
  (let* ((e (org-entity-get name))
	 (n (cdr (assq kind '((latex . 1) (html . 3) (ascii . 4)
			      (latin1 . 5) (utf8 . 6)))))
	 (r (and e n (nth n e))))
    (if (and e r
	     (not org-entities-ascii-explanatory)
	     (memq kind '(ascii latin1 utf8))
	     (= (string-to-char r) ?\[))
	(concat "\\" name)
      r)))

(defsubst org-entity-latex-math-p (name)
  "Does entity NAME require math mode in LaTeX?"
  (nth 2 (org-entity-get name)))

;; Helpfunctions to create a table for orgmode.org/worg/org-symbols.org

(defun org-entities-create-table ()
  "Create an Org mode table with all entities."
  (interactive)
  (let ((pos (point)) e latex mathp html latin utf8 name ascii)
    (insert "|Name|LaTeX code|LaTeX|HTML code |HTML|ASCII|Latin1|UTF-8\n|-\n")
    (mapc (lambda (e) (when (listp e)
			(setq name (car e)
			      latex (nth 1 e)
			      mathp (nth 2 e)
			      html (nth 3 e)
			      ascii (nth 4 e)
			      latin (nth 5 e)
			      utf8 (nth 6 e))
			(if (equal ascii "|") (setq ascii "\\vert"))
			(if (equal latin "|") (setq latin "\\vert"))
			(if (equal utf8  "|") (setq utf8  "\\vert"))
			(if (equal ascii "=>") (setq ascii "= >"))
			(if (equal latin "=>") (setq latin "= >"))
			(insert "|" name
				"|" (format "=%s=" latex)
				"|" (format (if mathp "$%s$" "$\\mbox{%s}$")
					    latex)
				"|" (format "=%s=" html) "|" html
				"|" ascii "|" latin "|" utf8
				"|\n")))
	  org-entities)
    (goto-char pos)
    (org-table-align)))

(defun org-entities-help ()
  "Create a Help buffer with all available entities."
  (interactive)
  (with-output-to-temp-buffer "*Org Entity Help*"
    (princ "Org-mode entities\n=================\n\n")
    (let ((ll (append '("* User-defined additions (variable org-entities-user)")
		      org-entities-user
		      org-entities))
	  e latex mathp html latin utf8 name ascii
	  (lastwasstring t)
	  (head (concat
		 "\n"
		 "   Symbol   Org entity        LaTeX code             HTML code\n"
		 "   -----------------------------------------------------------\n")))
      (while ll
	(setq e (pop ll))
	(if (stringp e)
	    (progn
	      (princ e)
	      (princ "\n")
	      (setq lastwasstring t))
	  (if lastwasstring (princ head))
	  (setq lastwasstring nil)
	  (setq name (car e)
		latex (nth 1 e)
		html (nth 3 e)
		utf8 (nth 6 e))
	  (princ (format "   %-8s \\%-16s %-22s %-13s\n"
			 utf8 name latex html))))))
  (with-current-buffer "*Org Entity Help*"
    (org-mode))
  (select-window (get-buffer-window "*Org Entity Help*")))


(defun replace-amp ()
  "Postprocess HTML file to unescape the ampersand."
  (interactive)
  (while (re-search-forward "<td>&amp;\\([^<;]+;\\)" nil t)
    (replace-match (concat "<td>&" (match-string 1)) t t)))

(provide 'org-entities)

;; Local variables:
;; coding: utf-8
;; End:

;;; org-entities.el ends here
