Mercurial > hgrepos > hgweb.cgi > yatex
annotate docs/yatexadd.doc @ 436:e78a87bc2c9e dev
current file treated as absolute path(YaTeX-preview-jump-line)
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Fri, 08 Jan 2016 08:18:54 +0859 |
parents | 0734be649cb8 |
children |
rev | line source |
---|---|
6 | 1 ------------------------------------------------------------------------ |
2 野鳥用付加関数の作成方法 | |
3 ------------------------------------------------------------------------ | |
4 | |
5 | |
6 【付加関数とは】 | |
7 | |
49 | 8 begin 型補完で、「tabular 環境を入力している時に、わたしの好み |
9 のスタイルが入らないなあ」などと思うことはありませんか。tabular | |
10 環境に限らず、LaTeX の環境の引数には、各人お決まりのフォーマット | |
11 があるものです。たとえば凝った表を書く時の tabular環境の引数は、 | |
12 かなり複雑なので、デフォルトの自動入力関数よりも、 | |
6 | 13 |
8 | 14 "{@{\vrule width 1pt\ }|||@{\ \vrule width 1pt}}" |
6 | 15 |
16 を挿入するだけの単純な関数のほうが、嬉しい人もいるでしょう。あるい | |
17 は、「そんなの要らない。他の tabular をコピーして来たほうが早い。」 | |
18 と思う人もいるでしょう。 | |
19 | |
20 YaTeX の付加関数は、あらかじめ○○環境用のお仕着せの特別関数を用 | |
21 意しておくのではなく、○○環境用の特別関数が欲しくなったら独自の関 | |
22 数を定義する、というコンセプトに基づくもので、付加関数の登録のため | |
23 の手続きをすることなく、関数を定義したその瞬間から使えるようになり | |
24 ます。「必要なのは、defun だけ」です。 | |
25 | |
26 | |
27 【準備】 | |
28 | |
29 さすがに、関数を書くだけでは使えません:-)。yatex-mode 起動時には、 | |
8 | 30 その関数を定義したファイルがロードされていなくてはなりません。関数 |
25 | 31 を定義するファイル名を yatexhks.el(またはバイトコンパイルした形式 |
32 の yatexhks.elc)にし、そのファイルを load-path 中に置いておけば、 | |
8 | 33 野鳥が自動的にロードします。それ以外のファイル名にする場合は、 |
16
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
34 yatex-mode-load-hook に付加関数を定義する Emacs-Lisp ファイルをロー |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
35 ドするような仕掛けを書いておくのがよいでしょう。 |
12 | 36 |
37 | |
38 【関数定義】 | |
39 | |
40 付加関数には、各LaTeXコマンドのオプション引数を返す形式のもの、 | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
41 section型補完の引数を返すもの、リジョン括りsection型補完の引数該当 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
42 部を処理するためのもの、三種類があります。ここでは便宜上その三つを、 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
43 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
44 a. 追加型付加関数 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
45 b. 引数型付加関数 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
46 c. 括り補完時付加関数 |
12 | 47 |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
48 と呼ぶことにします。 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
49 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
50 a は、以下の例のように、begin型補完では\begin{環境名}の直後に付 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
51 加する文字列、section型補完では LaTeX コマンド名と第一引数の間に位 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
52 置する文字列、maketitle型補完では LaTeX コマンド名の直後に位置する |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
53 文字列を返すような関数です。 |
12 | 54 |
55 (例) \begin{table}[ht] (付加関数名 YaTeX:table) | |
56 ~~~~ | |
57 \put(100,200){} (付加関数名 YaTeX:put) | |
58 ~~~~~~~~~ | |
59 \sum_{i=0}^{n} (付加関数名 YaTeX:sum) | |
60 ~~~~~~~~~~ | |
61 | |
62 追加型付加関数は『LaTeXコマンド名の前に YaTeX: をつけた名前』で定 | |
63 義します。 | |
64 | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
65 b は、以下のようにsection型コマンドの引数となる文字列を返す関数 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
66 です。 |
12 | 67 |
68 (例) \newcommand{\foo}{bar} (付加関数名 YaTeX::newcommand) | |
69 ~~~~ ~~~ | |
70 | |
71 引数型付加関数は『LaTeXコマンド名の前に YaTeX:: をつけた名前』で定 | |
16
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
72 義します。また引数型付加関数が呼ばれる時にはsection型コマンドの何 |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
73 番目の引数を入力しているのかが関数への引数として渡されます。したがっ |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
74 て、引数型付加関数は整数の引数を一つ取るものとして定義し、その引数 |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
75 の値により処理を決定することになります。 |
6 | 76 |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
77 (yatex.1.72の新機能) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
78 c は、既存テキストの一部をsection型コマンドの引数として括るとき |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
79 に、指定したりジョンの先頭と末尾の各ポイントを引数として呼ばれます。 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
80 たとえば、 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
81 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
82 5/3 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
83 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
84 というテキストをリジョン指定して [prefix] S でセクション型コマンド |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
85 で括りたいときに、括られるテキストに対してなんらかの処理をほどこし |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
86 たいときに呼ばれます。 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
87 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
88 (例) 5/3 ←5/3をリジョン指定し \frac で括る |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
89 \frac{5/3} ←5/3のポイント位置を引数に呼ばれる |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
90 ~~~ (付加関数 YaTeX::frac-region) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
91 |
6 | 92 |
12 | 93 【定義例】 |
94 | |
95 例えば、tabular環境のフォーマットとして、いつでも {|c|c|c|} を入 | |
96 れるだけで良いのなら、 | |
97 | |
98 (defun YaTeX:tabular () | |
99 "{|c|c|c|}") | |
100 | |
101 とだけ書けばよく、前述の、複雑な定型 tabular フォーマットを挿入す | |
102 るための関数を定義する場合は次のようにします。 | |
103 | |
104 (defun YaTeX:tabular () | |
105 "{@{\\vrule width 1pt\\ }|||@{\\ \\vrule width 1pt}}") | |
106 | |
107 この時、Emacs-Lisp 中の文字列では、\ 自身は \\ と表記することなど | |
108 に注意して下さい。 | |
109 | |
110 また、{} の中を、補完時に直接キーボードから読み込ませたい時は、 | |
6 | 111 |
12 | 112 (defun YaTeX:tabular () |
113 (concat "{" (read-string "Rule: ") "}")) | |
114 | |
115 などとすれば良いでしょう。 | |
116 | |
117 次に、引数型付加関数として \newcommand の引数を読み込む関数を定 | |
118 義する場合を例示します。\newcommand の第一引数は新たに定義するコマ | |
119 ンド名なので、必ず先頭に \ が来ます。第二引数はたいていの場合ミニ | |
120 バッファでは編集しづらいような複雑な定義を書くので、何も補完しない | |
121 方が良いでしょう。これを考慮して付加関数を定義すると以下のようなも | |
122 のになるでしょう。 | |
123 | |
124 (defun YaTeX::newcommand (n) ;nは引数の位置 | |
125 (cond | |
126 ((= n 1) ;第一引数ならコマンド名 | |
16
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
127 (read-string "Command: " "\\")) ;\を初期入力とする |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
128 ((= n 2) "") ;第二引数なら何もしない |
12 | 129 (t nil))) |
130 | |
131 なお、引数型付加関数が nil を返した場合は、通常の引数入力関数が呼 | |
132 ばれます。 | |
6 | 133 |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
134 最後に括り補完時付加関数の例として、既存テキストを \frac で括 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
135 る場合の例を示します。\frac は2つの引数を取り、\frac{a}{b} のよ |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
136 うにして、分数を表すときに利用するコマンドです。数学的には |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
137 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
138 a |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
139 a/b ⇔ ---- |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
140 b |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
141 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
142 と置き換え可能な記法です。LaTeXソースにa/bと書いたものを野鳥の括 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
143 り補完で\fracに括ると、以下のようになります。 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
144 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
145 \frac{a/b} |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
146 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
147 /の部分を }{ に置き換えれば正しい書き換えになります。このような |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
148 ことを対話的に半自動で行なうアドイン関数は以下のようにします。 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
149 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
150 (defun YaTeX::frac-region (beg end) ;リジョンの先頭と末尾 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
151 (catch 'done |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
152 (while (search-forward "/" end t) ;/がある間繰り返す |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
153 (goto-char (match-beginning 0)) ;/の位置に移動 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
154 (if (y-or-n-p "Replace this slash(/) to `}{'") |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
155 (throw 'done (replace-match "}{"))) ;置き換えて終了 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
156 (goto-char (match-end 0))))) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
157 |
6 | 158 |
159 【呼ばれ方】 | |
160 | |
8 | 161 野鳥本体は、begin型補完とsection型補完、およびmaketitle型補完の |
162 入力時に付加関数の存在を調べてから呼び出します。begin型補完の場合 | |
163 \begin{環境名} が自動入力された直後に呼び出されます。section型補完 | |
164 では第一引数の補完の直前、maketitle型補完の場合は、コマンド名の直 | |
12 | 165 後(一つのスペースを挿入する直前)に呼び出されます。引数型付加関数は、 |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
166 section型コマンドの引数の入力時にその都度呼ばれます。括り補完時付 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
70
diff
changeset
|
167 加関数は、LaTeXコマンドと{}がテキストに挿入された直後に呼ばれます。 |
6 | 168 |
169 | |
170 【参考】 | |
171 | |
172 付加関数の定義の例を yatexadd.el に用意しました。実際に独自の付 | |
173 加関数を定義する時の参考として下さい。 | |
174 | |
8 | 175 有用と思われる関数について、簡単に説明します。 |
176 | |
177 ・関数 YaTeX:read-position | |
178 引数 [] の中に入れてもよい文字を羅列した文字列。 | |
179 説明 [htb] などのような location 指定を作成します。何も入力せず | |
180 リターンを押すと、[]自体も省略されます。[]の中に来るべき文 | |
181 字が htbp に限られているなら、(YaTeX:read-position "htbp") | |
182 と呼び出します。 | |
183 | |
52 | 184 ・関数 YaTeX-cplread-with-learning |
185 引数 プロンプト | |
186 デフォルト補完テーブル変数シンボル | |
187 ユーザ補完テーブル変数シンボル | |
188 ローカル補完テーブル変数シンボル | |
189 説明 「プロンプト」というプロンプトを出し、補完入力を行います。 | |
190 三つの変数のテーブルの値を結合したものが補完候補として用 | |
191 いられ、新しい単語を入力すると自動的に学習されます。学習 | |
192 結果は ~/.yatexrc か ./.yatexrc に保存されます。使用例と | |
193 して YaTeX::documentstyle 関数の定義をごらんください。 | |
194 | |
54 | 195 ・関数 YaTeX:read-coordinates |
196 引数 基本プロンプト、X座標プロンプト、Y座標プロンプト(全て省略可) | |
197 説明 「基本プロンプト X座標プロンプト:」というプロンプトを出し | |
8 | 198 て、X座標を読み込み、「基本プロンプト Y座標プロンプト:」を |
199 出して、Y座標を読み込み、(X座標,Y座標) の様な形式を作成します。 | |
200 何も入力せずリターンを押しても、(,)が返されます。 | |
201 各プロンプトのデフォルトはそれぞれ、Dimension, X, Y です。 | |
202 | |
203 ・関数 YaTeX:check-comletion-type | |
204 引数 'begin または、'section または、'maketitle | |
205 説明 付加関数が呼ばれる時に、行われている補完の形式が、引数で与 | |
206 えたものであるかどうか調べ、そうでない場合にエラー終了する。 | |
207 なお、変数 YaTeX-current-completion-type に現在の補完の型 | |
208 を表わすシンボル(この関数の引数と同様)が格納されています。 | |
209 | |
6 | 210 |
211 【最後に】 | |
212 | |
213 快適な関数を定義したなら、そしてそれを公開してもよいと思われたな | |
214 ら、筆者までお送り下さい。次の yatexadd.el に取り込んで行きたいと | |
215 思います。 | |
216 | |
217 | |
69 | 218 広瀬雄二 |
70 | 219 yuuji@yatex.org |