summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/luatex/luaintro/04-04-10.lualtx
blob: 980bce488627e385f4807133c5d5bf43647f4e4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
%% 
%%  Ein Beispiel der DANTE-Edition
%%  
%%  1. Auflage
%% 
%%  Beispiel 04-04-10 auf Seite 94.
%% 
%%  Copyright (C) 2013 Herbert Voss
%% 
%%  It may be distributed and/or modified under the conditions
%%  of the LaTeX Project Public License, either version 1.3
%%  of this license or (at your option) any later version.
%% 
%%  See http://www.latex-project.org/lppl.txt for details.
%% 
%% 
%% ==== 
% Show page(s) 1
%% 
%% 
\documentclass[]{exaarticle}
\pagestyle{empty}
\setlength\textwidth{352.81416pt}
\setlength\parindent{0pt}
%StartShownPreambleCommands
\usepackage{luacode,libertine}
\begin{luacode}
  local translate={c='ĉ', g='ĝ', h='ĥ', j='ĵ', s='ŝ', u='û'}
  local function get_char_token(char)
    return token.create(unicode.utf8.byte(char))
  end
  local function get_token_char(tok)
    return tok[1] == 11 and unicode.utf8.char(tok[2])
  end
  local circumflex_token = get_char_token("^")
  local function is_circumflex(tok)
    return tok[1] == circumflex_token[1] and tok[2] == circumflex_token[2]
       and tok[3] == circumflex_token[3]
  end
  local function in_math_mode()
    local n = tex.nest[tex.nest.ptr]
    return n.mode == 235 or n.mode == -235
  end
  local function texperanto()
    local t = token.get_next()
    if not in_math_mode() and is_circumflex(t) then
      local u = token.get_next()
      local c = get_token_char(u)
      if c then
        local d = translate[c]
        if d then return get_char_token(d) else return {t, u} end
      else return {t, u} end
    else   return t end
  end
  luatexbase.add_to_callback("token_filter", texperanto, "texperanto")
\end{luacode}
%StopShownPreambleCommands
\begin{document}
^c ^g ^h ^j ^s ^u $a^2+b^2=c^2$ und $a^c\le h^j$
\end{document}