go-latex / latex

Go package for LaTeX
BSD 3-Clause "New" or "Revised" License
93 stars 13 forks source link

LaTeX accents replacement #27

Open ghost opened 4 years ago

ghost commented 4 years ago

Hi,

Hope you are all well !

Is it possible to handle LaTex accents replacement ?

# LaTeX accents replacement
latexAccents = [
  "à", "\`a", # Grave accents
  "è", "\`e",
  "ì", "\`\\i",
  "ò", "\`o",
  "ù", "\`u",
  "ỳ", "\`y",
  "À", "\`A",
  "È", "\`E",
  "Ì", "\`\\I",
  "Ò", "\`O",
  "Ù", "\`U",
  "Ỳ", "\`Y",
  "á", "\'a", # Acute accents
  "é", "\'e",
  "í", "\'\\i",
  "ó", "\'o",
  "ú", "\'u",
  "ý", "\'y",
  "Á", "\'A",
  "É", "\'E",
  "Í", "\'\\I",
  "Ó", "\'O",
  "Ú", "\'U",
  "Ý", "\'Y",
  "â", "\^a", # Circumflex
  "ê", "\^e",
  "î", "\^\\i",
  "ô", "\^o",
  "û", "\^u",
  "ŷ", "\^y",
  "Â", "\^A",
  "Ê", "\^E",
  "Î", "\^\\I",
  "Ô", "\^O",
  "Û", "\^U",
  "Ŷ", "\^Y",
  "ä", "\\"a",    # Umlaut or dieresis
  "ë", "\\"e",
  "ï", "\\"\i",
  "ö", "\\"o",
  "ü", "\\"u",
  "ÿ", "\\"y",
  "Ä", "\\"A",
  "Ë", "\\"E",
  "Ï", "\\"\I",
  "Ö", "\\"O",
  "Ü", "\\"U",
  "Ÿ", "\\"Y",
  "ç", "\c{c}",   # Cedilla
  "Ç", "\c{C}",
  "œ", "{\\oe}",   # Ligatures
  "Œ", "{\\OE}",
  "æ", "{\\ae}",
  "Æ", "{\\AE}",
  "å", "{\\aa}",
  "Å", "{\\AA}",
  "–", "--",   # Dashes
  "—", "---",
  "ø", "{\\o}",    # Misc latin-1 letters
  "Ø", "{\\O}",
  "ß", "{\\ss}",
  "¡", "{!`}",
  "¿", "{?`}",
  "\", "\\\",    # Characters that should be quoted
  "~", "\~",
  "&", "\&",
  "$", "\$",
  "{", "\{",
  "}", "\}",
  "%", "\%",
  "#", "\#",
  "_", "\_",
  "©", "\copyright", # Misc
  "ı", "{\\i}",
  "‘", "`",    #Quotes
  "’", "'",
  "“", "``",
  "”", "''",
  "‚", ",",
  "„", ",,",
  "", ",,"
]

Cheers, X

sbinet commented 3 years ago

apologies for the belated answer.

yes, I think it could make sense to have such a thing. for the "math TeX" renderer, we do the opposite (for math symbols, replacing their LaTeX "representation" with the proper UTF-8 symbol, if any).

we could have an internal/unicode2tex package that does the reverse.

want to give a stab at it? (I promise to review your PR in a more diligent fashion :P)