As mentioned in the comments, the source for detexify is available on GitHub at https://github.com/kirel/detexify.
The symbols database is provided at lib/latex/symbols.yaml
in a YAML format (sample below) which is easily extensible and satisfies your requirements for information about the required package(s) and mode (text or math).
# Table 212: wasysym Biological Symbols
- package: wasysym
bothmodes:
- \female
- \male
- package: skull
mathmode:
- \skull
# Table 254: wasysym General Symbols
- package: wasysym
textmode:
- \LEFTarrow
# <...>
- \recorder
bothmodes:
- \checked #
# <...>
- \invdiameter #
SVG output can be created by adapting a rake
task provided in lib/rake/symbol_task.rb
. I present my initial adaptation of this code below. Disclaimer: I am a newbie to Ruby, and there are likely better ways to do this since I'm stripping away most of Daniel's code here. Take this as a starting point rather than the standard. :-)
require 'rake/tasklib'
require 'erb'
require 'latex/symbol'
class SymbolTask < Rake::TaskLib
TEMPLATE = ERB.new <<-LATEX #open('template.tex.erb').read
\\documentclass[10pt]{article}
\\usepackage[utf8]{inputenc}
<%= @packages %>
\\pagestyle{empty}
\\begin{document}
<%= @command %>
\\end{document}
LATEX
TMP = 'tmp'
OUT = 'images/latex'
attr_accessor :name, :tmp, :out
# initialize sets the name and calls a block to get
# the rest of the options
def initialize(name = :symbols)
@name = name
yield self if block_given?
define
end
# define creates the new task(s)
def define
#desc "prepare necessary directories"
#task :prepare do
directory TMP
directory OUT
#end
all_image_tasks = Latex::Symbol::List.map do |symbol|
define_single_tex_task symbol
define_single_dvi_task symbol
define_single_image_task symbol
end
desc "create svg images from all symbols"
task :gen_svg => all_image_tasks
end
def define_single_image_task symbol
file "#{File.join(OUT, symbol.filename)}.svg" => [OUT, "#{File.join(TMP, symbol.filename)}.dvi"] do |t|
# Now convert to image
puts "Creating image... #{t.name}"
sh %|dvisvgm -n #{File.join(TMP, symbol.filename)}.dvi #{t.name}| do |ok, res|
if ! ok
puts "Major Failure creating image! (status = #{res.exitstatus})"
end
end
end
"#{File.join(OUT, symbol.filename)}.svg" # need the names
end
def define_single_dvi_task symbol
file "#{File.join(TMP, symbol.filename)}.dvi" => [TMP, "#{File.join(TMP, symbol.filename)}.tex"] do
puts "Generating dvi for #{symbol}..."
sh %|latex -interaction=batchmode -output-directory=#{TMP} #{File.join(TMP, symbol.filename)}.tex| do |ok, res|
if ! ok
puts "Major Failure creating dvi! (status = #{res.exitstatus})"
end
end
end
end
def define_single_tex_task symbol
file "#{File.join(TMP, symbol.filename)}.tex" => TMP do |t|
open(t.name, 'w+') do |texfile|
# setup variables
@packages = ''
@packages << "\\usepackage{#{symbol[:package]}}\n" if symbol[:package]
@packages << "\\usepackage[#{symbol[:fontenc]}]{fontenc}\n" if symbol[:fontenc]
@command = symbol.mathmode ? "$#{symbol.command}$" : symbol.command
# write symbol to tempfile
puts "Generating latex for #{symbol}..."
texfile.puts TEMPLATE.result(binding)
end
end
end
end
I made these modifications on a clone of the detexify repository, but the only files required are lib/rake/symbol_task.rb
, lib/latex/symbol.rb
, and lib/latex/symbols.yaml
.
To build all SVG outputs, execute rake gen_svg
at a Ruby command prompt. dvisvgm
is required; alternatively, the Ruby code could be modified to use pdflatex
with pdf2svg
(untested) or Inkscape (on the command line) to perform the conversion to SVG.
For your disappointment, none. They are the same.
If you run
\documentclass{standalone}
\begin{document}
\(\show\lnot a \, \show\neg a\)
\end{document}
you'll get:
> \lnot=\mathchar"23A.
l.3 \(\show\lnot
a \, \show\neg a\)
?
> \neg=\mathchar"23A.
l.3 \(\show\lnot a \, \show\neg
a\)
which shows that both are \mathchar"23A
.
In fact, in plain.tex
one finds:
\mathchardef\neg="023A \let\lnot=\neg
The same appears for other symbols as well:
\mathchardef\wedge="225E \let\land=\wedge
\mathchardef\vee="225F \let\lor=\vee
\def\neq{\not=} \let\ne=\neq
\mathchardef\leq="3214 \let\le=\leq
\mathchardef\geq="3215 \let\ge=\geq
\mathchardef\ni="3233 \let\owns=\ni
\mathchardef\leftarrow="3220 \let\gets=\leftarrow
\mathchardef\rightarrow="3221 \let\to=\rightarrow
My guess for the reason of this is that in different fields of applications these symbols get different names, so they have different names to make their utilization more intuitive.
In LaTeX, what happens is basically the same, but with a few more bells and whistles:
\DeclareMathSymbol{\neg}{\mathord}{symbols}{"3A}
\let\lnot=\neg
This can be found in fontmath.ltx
(loaded by latex.ltx
).
Best Answer
The commands
\|
and\parallel
print the same symbol; here are their definitions infontmath.ltx
:The meaning of the first definition is that
\Vert
(of which\|
is an alias) prints the glyph in slot"6B
of the font in mathgroupsymbols
when requested at normal size and, when not used in the context of delimiters (after\left
,\right
,\bigl
,\bigr
and friends) it behaves as an ordinary symbol.The definition of
\parallel
tells TeX to use the very same glyph, but treating it as a relation symbol. Sowill result in
whereas
will produce
where
$\alpha\|\beta$
would producewith no spaces around the double bar. In Unicode,
\Vert
is U+2016 DOUBLE VERTICAL LINE, while\parallel
is U+2225 PARALLEL TO.The command
\textdoublepipe
is found intipa
and produces the symbol Į (Unicode U+01C1 LATIN LETTER LATERAL CLICK) which is glyph 123 in a T3 encoded font. Also\textdoublevertline
is defined bytipa
and refers to glyph 147 in a T3 encoded fontThe manual of
tipa
refers to the former as alveolar lateral click and to the latter as major (intonation) group; according to http://en.wikipedia.org/wiki/Prosodic_unit, this is the same U+2016 as before.So, even if the four glyphs are similar, their meaning is different and should be used in the proper context.