6

Esperanto uses an alphabet that is largely ASCII, but also includes the letters ĉ, ĝ, ĥ, ĵ, ŝ, and ŭ. At the same time, some ASCII letters are not used. When you're limited to just ASCII there's a spelling standard where accented letters are written without the accent and then an 'x' (not normally used in Esperanto) is written after the letter. So to write 'ĉ' you use 'cx' instead.

Is there a way to setup an environment within a Latex document that would automatically convert instances of cx, gx, sx and so on into the correct accented letter during compilation? I know that you could use the \^ and \v commands, \^{c}, \^{g}, \v{s} and such, to achieve the same result, but when typing a lot of accented letters it's rather cumbersome. I could also type out the whole document without accented letters and then convert it using the editor's search/replace function, but this seems like something that the compiler could do if I just knew the right commands.

2
  • The babel package provides Esperanto support, the accented characters are typeset by making ^ active: ^c becomes ĉ. Not exactly what you are looking for, but definitely less cumbersome. (Besides, bable takes also care of correct hyphenation.)
    – Daniel
    Jun 18, 2015 at 22:52
  • Ah, I will also keep this in mind.
    – Lokathor
    Jun 18, 2015 at 22:56

1 Answer 1

7

It's possible using xparse and environ; the text is absorbed and the strings are converted to the accented forms and then delivered.

\documentclass{article}

\usepackage{xparse,environ}

\ExplSyntaxOn
\NewDocumentCommand{\textesperanto}{m}
 {
  \lokathor_convert_esperanto:n { #1 }
 }
\NewEnviron{esperanto}
 {
  \lokathor_convert_esperanto:V \BODY
 }

\tl_new:N \l__lokathor_text_tl

\cs_new_protected:Nn \lokathor_convert_esperanto:n
 {
  \tl_set:Nn \l__lokathor_text_tl { #1 }
  \tl_replace_all:Nnn \l__lokathor_text_tl { CX } { \^C }
  \tl_replace_all:Nnn \l__lokathor_text_tl { Cx } { \^C }
  \tl_replace_all:Nnn \l__lokathor_text_tl { cx } { \^c }
  \tl_replace_all:Nnn \l__lokathor_text_tl { GX } { \^G }
  \tl_replace_all:Nnn \l__lokathor_text_tl { Gx } { \^G }
  \tl_replace_all:Nnn \l__lokathor_text_tl { gx } { \^g }
  \tl_replace_all:Nnn \l__lokathor_text_tl { HX } { \^H }
  \tl_replace_all:Nnn \l__lokathor_text_tl { Hx } { \^H }
  \tl_replace_all:Nnn \l__lokathor_text_tl { hx } { \^h }
  \tl_replace_all:Nnn \l__lokathor_text_tl { JX } { \^J }
  \tl_replace_all:Nnn \l__lokathor_text_tl { Jx } { \^J }
  \tl_replace_all:Nnn \l__lokathor_text_tl { jx } { \^{\j} }
  \tl_replace_all:Nnn \l__lokathor_text_tl { SX } { \^S }
  \tl_replace_all:Nnn \l__lokathor_text_tl { Sx } { \^S }
  \tl_replace_all:Nnn \l__lokathor_text_tl { sx } { \^s }
  \tl_replace_all:Nnn \l__lokathor_text_tl { UX } { \u{U} }
  \tl_replace_all:Nnn \l__lokathor_text_tl { Ux } { \u{U} }
  \tl_replace_all:Nnn \l__lokathor_text_tl { ux } { \u{u} }
  \l__lokathor_text_tl
 }
\cs_generate_variant:Nn \lokathor_convert_esperanto:n { V }
\ExplSyntaxOff

\begin{document}

\begin{esperanto}
Italio aux Italujo (itale: Por auxskulti bv alklaki cxi ligon ``Italia'' Italia ),
oficiale Itala Respubliko (itale: Repubblica Italiana), estas sxtato de 
Suda Euxropo.

Nomata ankaux per antonomazioj, kiel ``la Boto'' pro gxia formo simila al boto 
kaj ``bela lando'' (itale ``bel paese'') pro gxia klimato kaj pro gxia naturaj kaj 
artaj belajxoj, geografie Italio estas formata el tri partoj: unu kontinenta, 
limita de Alpoj kaj de konvencia linio kiu kunligas La Spezia kun Rimini, unu 
duoninsula, kiu estas formata de cetera Italio kaj unu insula, kiu entenas la 
du plejgrandajn insulojn de la Mediteraneo, Sardinio kaj Sicilio, kie en la 
insulo de Pantelleria estas la malplej longa distanco de Afriko, je distanco 
de preskaux 70 kilometroj. La teritoriaj limoj etendigxas entute en 1800 kilometroj, 
dum la marbordoj longas 7500 kilometrojn.
\end{esperanto}

\textesperanto{CXGXHXJXSXUX}

\textesperanto{CxGxHxJxSxUx}

\textesperanto{cxgxhxjxsxux}

\end{document}

enter image description here

The text is from Wikipedia.


A different approach is with XeLaTeX. Prepare a file esperanto.map containing

; TECkit mapping for TeX input conventions <-> Unicode characters

LHSName "TeX-text"
RHSName "UNICODE"

pass(Unicode)

; ligatures from Knuth's original CMR fonts
U+002D U+002D           <>  U+2013  ; -- -> en dash
U+002D U+002D U+002D    <>  U+2014  ; --- -> em dash

U+0027          <>  U+2019  ; ' -> right single quote
U+0027 U+0027   <>  U+201D  ; '' -> right double quote
U+0022           >  U+201D  ; " -> right double quote

U+0060          <>  U+2018  ; ` -> left single quote
U+0060 U+0060   <>  U+201C  ; `` -> left double quote

U+0021 U+0060   <>  U+00A1  ; !` -> inverted exclam
U+003F U+0060   <>  U+00BF  ; ?` -> inverted question

; additions supported in T1 encoding
U+002C U+002C   <>  U+201E  ; ,, -> DOUBLE LOW-9 QUOTATION MARK
U+003C U+003C   <>  U+00AB  ; << -> LEFT POINTING GUILLEMET
U+003E U+003E   <>  U+00BB  ; >> -> RIGHT POINTING GUILLEMET

; additions for Esperanto
; cx
U+0043 U+0058   <>      U+0108 ; LATIN CAPITAL LETTER C WITH CIRCUMFLEX
U+0043 U+0078   <>      U+0108 ; LATIN CAPITAL LETTER C WITH CIRCUMFLEX
U+0063 U+0078   <>      U+0109 ; LATIN SMALL LETTER C WITH CIRCUMFLEX
; gx
U+0047 U+0058   <>      U+011C ; LATIN CAPITAL LETTER G WITH CIRCUMFLEX
U+0047 U+0078   <>      U+011C ; LATIN CAPITAL LETTER G WITH CIRCUMFLEX
U+0067 U+0078   <>      U+011D ; LATIN SMALL LETTER G WITH CIRCUMFLEX
; hx
U+0048 U+0058   <>      U+0124 ; LATIN CAPITAL LETTER H WITH CIRCUMFLEX
U+0048 U+0078   <>      U+0124 ; LATIN CAPITAL LETTER H WITH CIRCUMFLEX
U+0068 U+0078   <>      U+0125 ; LATIN SMALL LETTER H WITH CIRCUMFLEX
; jx
U+004A U+0058   <>      U+0134 ; LATIN CAPITAL LETTER J WITH CIRCUMFLEX
U+004A U+0078   <>      U+0134 ; LATIN CAPITAL LETTER J WITH CIRCUMFLEX
U+006A U+0078   <>      U+0135 ; LATIN SMALL LETTER J WITH CIRCUMFLEX
; sx
U+0053 U+0058   <>      U+015C ; LATIN CAPITAL LETTER S WITH CIRCUMFLEX
U+0053 U+0078   <>      U+015C ; LATIN CAPITAL LETTER S WITH CIRCUMFLEX
U+0073 U+0078   <>      U+015D ; LATIN SMALL LETTER S WITH CIRCUMFLEX
; ux
U+0055 U+0058   <>      U+016C ; LATIN CAPITAL LETTER U WITH BREVE
U+0055 U+0078   <>      U+016C ; LATIN CAPITAL LETTER U WITH BREVE
U+0075 U+0078   <>      U+016D ; LATIN SMALL LETTER U WITH BREVE

The first part is the standard tex-text.map.

Compile the file with

teckit_compile esperanto.map

Now a test to be compiled with XeLaTeX.

\documentclass{article}

\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{esperanto}
\newfontfamily{\esperantofont}{Linux Libertine O}[Mapping=esperanto]

\begin{document}

Italio aux Italujo (itale: Por auxskulti bv alklaki cxi ligon ``Italia'' Italia ),
oficiale Itala Respubliko (itale: Repubblica Italiana), estas sxtato de 
Suda Euxropo.

Nomata ankaux per antonomazioj, kiel ``la Boto'' pro gxia formo simila al boto 
kaj ``bela lando'' (itale ``bel paese'') pro gxia klimato kaj pro gxia naturaj kaj 
artaj belajxoj, geografie Italio estas formata el tri partoj: unu kontinenta, 
limita de Alpoj kaj de konvencia linio kiu kunligas La Spezia kun Rimini, unu 
duoninsula, kiu estas formata de cetera Italio kaj unu insula, kiu entenas la 
du plejgrandajn insulojn de la Mediteraneo, Sardinio kaj Sicilio, kie en la 
insulo de Pantelleria estas la malplej longa distanco de Afriko, je distanco 
de preskaux 70 kilometroj. La teritoriaj limoj etendigxas entute en 1800 kilometroj, 
dum la marbordoj longas 7500 kilometrojn.

CXGXHXJXSXUX

CxGxHxJxSxUx

cxgxhxjxsxux

\end{document}

enter image description here

Of course, in this case, direct Unicode input is also possible.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .