Difference between revisions of "Unicode-symbols"

From HaskellWiki
Jump to navigation Jump to search
(→‎Input methods: Added section for Vim)
Line 63: Line 63:
   
 
These symbols are all very nice but how do you type them?
 
These symbols are all very nice but how do you type them?
  +
  +
Wikipedia has a helpful article: http://en.wikipedia.org/wiki/Unicode_input
   
 
(''please add info for other editors'')
 
(''please add info for other editors'')
Line 105: Line 107:
   
 
Use Agda's [http://wiki.portal.chalmers.se/agda/pmwiki.php?n=Docs.UnicodeInput input method].
 
Use Agda's [http://wiki.portal.chalmers.se/agda/pmwiki.php?n=Docs.UnicodeInput input method].
  +
  +
=== Vim ===
  +
  +
(''real Vim users might want to expand this section'')
  +
  +
'''Direct'''
  +
  +
* Decimal value: type '''C-Vnnn''' where 0 ≤ nnn ≤ 255.
  +
* Octal value: type '''C-VOnnn''' or '''C-Vonnn''' where 0 ≤ nnn ≤ 377.
  +
* Hex value: type '''C-VXnn''' or '''C-Vxnn''' where 0 ≤ nn ≤ FF.
  +
* Hex value for BMP codepoints: type '''C-Vunnnn''' where 0 ≤ nnnn ≤ FFFF.
  +
* Hex value for any codepoint: type '''C-VUnnnnnnnn''' where 0 ≤ nnnnnnnn ≤ FFFFFFFF.
  +
   
 
=== System wide ===
 
=== System wide ===

Revision as of 20:51, 13 February 2011


Overview

An overview of the packages that provide Unicode symbols.

Naming: A package X-unicode-symbols defines new symbols for functions and operators from the package X.

All symbols are documented with their actual definition and information regarding their Unicode code point. They should be completely interchangeable with their definitions.

Alternatives for existing operators have the same fixity. New operators will have a suitable fixity defined.

UnicodeSyntax

GHC offers the UnicodeSyntax language extension. If you decide to use Unicode in your Haskell source then this extension can greatly improve how it looks.

Simply put the following above a module to enable unicode syntax:

 {-# LANGUAGE UnicodeSyntax #-}

base-unicode-symbols

Extra symbols for the base package.

 API docs: http://hackage.haskell.org/package/base-unicode-symbols
 darcs get http://code.haskell.org/~roelvandijk/code/base-unicode-symbols

Problematic symbols

Original Symbol Code point Name
not ¬ U+AC NOT SIGN

The problem with this symbol is that you would like to use it as an unary prefix operator:

 ¬(¬x) ≡ x

Unfortunately this is not valid Haskell. The following is:

 (¬)((¬)x) ≡ x

But you can hardly call that an improvement over the simple:

 not (not x) ≡ x

New symbol ideas

(please add your own)

containers-unicode-symbols

Extra symbols for the containers package.

 API docs: http://hackage.haskell.org/package/containers-unicode-symbols
 darcs get http://code.haskell.org/~roelvandijk/code/containers-unicode-symbols

New symbol ideas

(please add your own)

Input methods

These symbols are all very nice but how do you type them?

Wikipedia has a helpful article: http://en.wikipedia.org/wiki/Unicode_input

(please add info for other editors)

Emacs

Direct

Enter symbols directly: C-x 8 RET (ucs-insert), then type either the character's name or its hexadecimal code point.

Custom input method

I wrote my own input method:

 darcs get http://code.haskell.org/~roelvandijk/code/haskell-unicode-input-method
 

or (while code.haskell.org is down)

 darcs get http://bifunctor.homelinux.net/~roel/haskell-unicode-input-method

To automically load in haskell-mode put the following code in your .emacs file:

 (require 'haskell-unicode-input-method)
 (add-hook 'haskell-mode-hook 
   (lambda () (set-input-method "haskell-unicode")))

Make sure the directory containing the .elisp file is in your load-path, for example:

 (add-to-list 'load-path "~/.elisp/haskell-unicode-input-method")

To manually enable use M-x set-input-method or C-x RET C-\ with haskell-unicode. Note that the elisp file must be evaluated for this to work.

Now you can simply type -> and it is immediately replaced with . Use C-\ to toggle the input method. To see a table of all key sequences use M-x describe-input-method haskell-unicode. A sequence like <= is ambiguous and can mean either or . Typing it presents you with a choice. Type 1 or 2 to select an option or keep typing to use the default option.

If you don't like the highlighting of partially matching tokens you can turn it off:

 (setq input-method-highlight-flag nil)

Abbrev mode

The Abbrev mode is not suitable since it only deals with words, not operators.

Agda

Use Agda's input method.

Vim

(real Vim users might want to expand this section)

Direct

  • Decimal value: type C-Vnnn where 0 ≤ nnn ≤ 255.
  • Octal value: type C-VOnnn or C-Vonnn where 0 ≤ nnn ≤ 377.
  • Hex value: type C-VXnn or C-Vxnn where 0 ≤ nn ≤ FF.
  • Hex value for BMP codepoints: type C-Vunnnn where 0 ≤ nnnn ≤ FFFF.
  • Hex value for any codepoint: type C-VUnnnnnnnn where 0 ≤ nnnnnnnn ≤ FFFFFFFF.


System wide

m17n input methods

A set of input methods has been written by Urs Holzer for the m17n library. The main goal of Urs is to build input methods for mathematical characters. However, most of the symbols used in the *-unicode-symbols packages can be written using Urs's methods. More information is available at Input Methods for Mathematics page. For most Linux distributions, just download a tarball, extract *.mim files to /usr/share/m17n and enable iBus for input methods.

Fonts

The following free fonts have good Unicode coverage: