Skip to content

Commit 197e0e7

Browse files
committed
Add g:latex_to_unicode_keymap option + docs
1 parent bb71330 commit 197e0e7

File tree

6 files changed

+128
-41
lines changed

6 files changed

+128
-41
lines changed

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ The remainder of this README will only give an overview of some of the features:
2424
This plug-in adds some functionality to substitute LaTeX code sequences (e.g. `\alpha`) with corresponding
2525
Unicode symbols (e.g. `α`). By default, these substitutions must be triggered explicitly by pressing the
2626
<kbd>Tab</kbd> key, as in the Julia command line (the REPL); however, an automatic, as-you-type mode can also
27-
be activated.
27+
be activated, and a method based on keymap is also available.
2828

2929
This feature also works in command mode, e.g. when searching the files with the `/` or `?` commands, but the
30-
as-you-type mode is not available.
30+
as-you-type mode is not available (the keymap-based version is though, and it also works with some Vim
31+
commands like `f` and `t`).
3132

3233
By default, this feature is only active when editing Julia files. However, it can be also enabled with
3334
other file types, and even turned on/off on the fly regardless of the file type.
@@ -118,6 +119,20 @@ also need to give the command `:call LaTeXtoUnicode#Init()` for the change to ta
118119

119120
This feature is not available with Vim versions lower then 7.4.
120121

122+
### LaTeX-to-Unicode via keymap
123+
124+
A different susbstitution mode based on keymaps can be activated with `:let g:latex_to_unicode_keymap = 1`,
125+
e.g. by putting it into your `.vimrc` file. This works similarly to the as-you-type method described above,
126+
but it has the advantage that it works under more circumstances, e.g. in command-line mode when searching with
127+
`/` or `?`, and when using the `f` and `t` commands.
128+
The disadvantages are that you don't see the whole sequence as you're typing it, and no suggestions or partial
129+
completions are available, thus you need to know the substitutions (see `:help L2U`), and to type them
130+
correctly in full.
131+
Another difference is that there is a timeout like for any other mapping.
132+
133+
If you use this method, it is advisable to disable the other two methods, setting both `g:latex_to_unicode_tab`
134+
and `g:latex_to_unicode_auto` to `0`.
135+
121136
### LaTeX-to-Unicode on other file types
122137

123138
By default, the LaTeX-to-Unicode substitutions are only active when editing Julia files. However, you can use

autoload/LaTeXtoUnicode.vim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ function! s:L2U_Setup()
1919
if !has_key(b:, "l2u_cmdtab_set")
2020
let b:l2u_cmdtab_set = 0
2121
endif
22+
if !has_key(b:, "l2u_keymap_set")
23+
let b:l2u_keymap_set = 0
24+
endif
2225

2326
" Did we activate the L2U as-you-type substitutions?
2427
if !has_key(b:, "l2u_autosub_set")
@@ -600,6 +603,21 @@ function! s:L2U_UnsetAutoSub()
600603
let b:l2u_autosub_set = 0
601604
endfunction
602605

606+
function! s:L2U_SetKeymap()
607+
if !b:l2u_keymap_set && get(g:, "latex_to_unicode_keymap", 0) && b:l2u_enabled
608+
setlocal keymap=latex2unicode
609+
let b:l2u_keymap_set = 1
610+
endif
611+
endfunction
612+
613+
function! s:L2U_UnsetKeymap()
614+
if !b:l2u_keymap_set
615+
return
616+
endif
617+
setlocal keymap=
618+
let b:l2u_keymap_set = 0
619+
endfunction
620+
603621
" Initialization. Can be used to re-init when global settings have changed.
604622
function! LaTeXtoUnicode#Init(...)
605623
let wait_insert_enter = a:0 > 0 ? a:1 : 1
@@ -612,9 +630,11 @@ function! LaTeXtoUnicode#Init(...)
612630

613631
call s:L2U_UnsetTab()
614632
call s:L2U_UnsetAutoSub()
633+
call s:L2U_UnsetKeymap()
615634

616635
call s:L2U_SetTab(wait_insert_enter)
617636
call s:L2U_SetAutoSub(wait_insert_enter)
637+
call s:L2U_SetKeymap()
618638
endfunction
619639

620640
function! LaTeXtoUnicode#Toggle()

autoload/julia_latex_symbols.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
" This file is autogenerated from the script 'generate_latex_symbols_table.jl'
2-
" The symbols are based on Julia version 0.7.0-rc2.0
2+
" The symbols are based on Julia version 1.1.0-DEV.695
33

44
scriptencoding utf-8
55

doc/julia-vim-L2U-table.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ julia-vim-L2U-table.txt LaTeX-to-Unicode reference table
44
LATEX-TO-UNICODE REFERENCE TABLE *L2U-ref* *julia-vim-L2U-reference*
55

66
Note: This file is autogenerated from the script 'generate_latex_symbols_table.jl'
7-
The symbols are based on the documentation of Julia version 0.7.0-rc2.0
7+
The symbols are based on the documentation of Julia version 1.1.0-DEV.695
88
See |julia-vim| for the LaTeX-to-Unicode manual.
99

1010
Code point(s) Character(s) Tab completion sequence(s) Unicode name(s)~

doc/julia-vim-L2U.txt

Lines changed: 88 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ License: MIT license {{{
2020
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2121
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2222
}}}
23-
2423
CONTENTS *julia-vim-L2U*
2524

2625
LaTeX-to-Unicode substitutions |julia-vim-L2U-introdction|
2726
Via Tab key |julia-vim-L2U-tab|
2827
As you type |julia-vim-L2U-as-you-type|
28+
Via Keymap |julia-vim-L2U-keymap|
2929
On different file types |julia-vim-L2U-file-types|
3030
Enabling and disabling |julia-vim-L2U-enable-disable|
3131
Variables |julia-vim-L2U-variables|
@@ -34,38 +34,54 @@ Functions |julia-vim-L2U-functions|
3434
==============================================================================
3535
LATEX TO UNICODE *julia-vim-L2U-introduction*
3636

37-
In the Julia REPL, entering a LaTeX sequence such as `\alpha` and pressing the
38-
<Tab> key substitutes it with a Unicode character such as `α`. The Julia REPL
39-
also provides partial completions, and suggestions for possible completions
40-
upon repeated pressing of the <Tab> key. Emojis are also available, with
41-
their names written between colons, e.g. `\:interrobang:` produces `⁉`.
42-
43-
This Vim plug-in provides the same functionality, with some extensions:
44-
- when a partial sequence is found, suggestions are presented in a menu
45-
together with their Unicode counterpart; the exact behaviour of this
46-
feature can be customized, see |julia-vim-L2U-tab|
47-
- optionally, symbols are substituted on the fly as you type them, see
48-
|julia-vim-L2U-as-you-type|
49-
50-
In Vim |Command-line| mode, e.g. when searching with the |/| or |?| commands, the
51-
default behavior is very similar, but slightly more limited: there are no
52-
suggestions, and the as-you-type substitutions are not avaliable. By default
53-
both <Tab> and <S-Tab> are mapped in command-line mode (the latter for
54-
backward compatibility reasons), but this can be customized if needed, see
55-
|julia-vim-L2U-cmdmode|.
37+
In the Julia REPL, entering a LaTeX-like sequence such as `\alpha` and pressing
38+
the <Tab> key substitutes it with a Unicode character such as `α`. The Julia
39+
REPL also provides partial completions, and suggestions for possible
40+
completions upon repeated pressing of the <Tab> key. Emojis are also
41+
available, with their names written between colons, e.g. `\:interrobang:`
42+
produces `⁉`.
43+
44+
See |julia-vim-L2U-reference| for the complete table of substitutions.
45+
46+
This Vim plug-in also provides the functionality needed to convert LaTeX
47+
input sequences into Unicode characters. There are 3 different methods
48+
available:
49+
50+
1. The default one is the most similar to the Julia one: substitutions are
51+
triggered by pressing the <Tab> key; if a partial match is found a list
52+
of suggested completions is presented in a menu together with their
53+
Unicode counterpart. The exact behaviour of this feature can be
54+
customized, see |julia-vim-L2U-tab|.
55+
56+
2. The second one substitutes symbols on the fly as you type, but only in
57+
|Insert| mode. See |julia-vim-L2U-as-you-type|.
5658

57-
By default, this feature is only active when editing Julia files. However, it
58-
can be also enabled with other file types, see |julia-vim-L2U-file-types|, and
59-
even turned on/off on the fly regardless of the file type, see
60-
|julia-vim-L2U-enable-disable|.
59+
3. The third is based on |keymap|. It also substitutes as-you-type, but it
60+
doesn't show you the full LaTeX sequence as you're typing it, and there
61+
is a time-out. Its main advantage over the previous one is that can be
62+
used in more circumstances, e.g. in |Command-line| mode or when searching
63+
for a character with |f| or |t|, as explained in |language-mapping|. See
64+
|julia-vim-L2U-keymap|.
65+
66+
The first two methods are independent and can be used together without issues.
67+
The third one is best used by its own, disabling the other two, to avoid
68+
confusion.
69+
70+
The default configuration is to use the first method, and it's only active
71+
when editing Julia files. It only works in |Insert| and |Command-line| modes.
72+
73+
It is possible to enable it with other file types, see
74+
|julia-vim-L2U-file-types|, and it can be even turned on/off on the fly
75+
regardless of the file type, see |julia-vim-L2U-enable-disable|.
76+
77+
In |Command-line| mode, e.g. when searching with the |/| or |?| commands, the
78+
default behavior is very similar, but slightly more limited, see
79+
|julia-vim-L2U-cmdmode|.
6180

6281
These features only work as described with Vim version 7.4 or higher. Tab
6382
completion can still be made available on lower Vim versions, see
6483
|julia-vim-L2U-workaround|.
6584

66-
See |julia-vim-L2U-reference| for the complete table of the available
67-
LaTeX-to-Unicode substitutions.
68-
6985
See |julia-vim| for the general reference about the other features of the
7086
julia-vim plug-in.
7187

@@ -82,7 +98,7 @@ mapping assigned to it, such that when the <Tab> key is pressed the plug-in
8298
looks for potential LaTeX symbol matches before the cursor, and if it fails to
8399
find anything of interest it will fall-back to the previous mapping for <Tab>
84100
(with default Vim settings, this means it will insert a literal <Tab>; but if
85-
you have defined dome other behaviour for that key, e.g. by installing another
101+
you have defined some other behavior for that key, e.g. by installing another
86102
plug-in such as supertab (https://github.com/ervandew/supertab) than that will
87103
be used).
88104

@@ -128,13 +144,13 @@ setting.
128144

129145
Command-line mode *julia-vim-L2U-cmdmode*
130146

131-
In |Command-line| mode, the behavior is largely the same except that both <Tab> and
132-
<S-Tab> are mapped by default, and the functionality is slightly more limited.
133-
No suggestions are shown for partial completions. Pre-existsing user-defined
134-
mappings of <Tab> are overridden, and in case of no L2U matches the fallback
135-
behavior is the standard Vim one. In order to avoid that, the
147+
In |Command-line| mode, the behavior is largely the same except that both
148+
<Tab> and <S-Tab> are mapped by default, and the functionality is slightly
149+
more limited. No suggestions are shown for partial completions. Pre-existing
150+
user-defined mappings of <Tab> are overridden. In order to avoid that, the
136151
completion can be mapped onto a defferent key combination, see
137-
|g:latex_to_unicode_cmd_mapping|.
152+
|g:latex_to_unicode_cmd_mapping|. When using <Tab>, if no matches are found
153+
the behavior falls back to the standard Vim command-line completion.
138154

139155
Vim versions lower than 7.4 *julia-vim-L2U-workaround*
140156

@@ -174,6 +190,25 @@ This feature does not currently work with emojis.
174190

175191
This feature does not interfere with the <Tab> based substitution.
176192

193+
------------------------------------------------------------------------------
194+
LATEX TO UNICODE VIA KEYMAP *julia-vim-L2U-keymap*
195+
196+
This method is somewhat similar to the as-you-type one described above, but it
197+
uses |keymap| to generate the mappings. This has the advantage that it works
198+
in more circumstances, e.g. in |Command-line| mode or when searching within a
199+
line with |f| or |t| (since it uses |language-mapping| underneath). It can
200+
also be easily turned on or off like any other keymap (see |i_CTRL-^| and
201+
|c_CTRL-^|).
202+
The disadvantages are that you don't see the whole sequence as you're typing
203+
it, and no suggestions or partial completions are available, thus you need to
204+
know the substitutions (see |julia-vim-L2U-reference|), and to type them
205+
correctly in full.
206+
Another difference is that there is a |timeout| like for any other mapping.
207+
208+
In order to use this method, set |g:latex_to_unicode_keymap| to `1`.
209+
If you do so, it is advisable to disable the other two methods,
210+
setting both |g:latex_to_unicode_tab| and |g:latex_to_unicode_auto| to `0`.
211+
177212
------------------------------------------------------------------------------
178213
LATEX TO UNICODE ON DIFFERENT FILE TYPES *julia-vim-L2U-file-types*
179214

@@ -271,15 +306,15 @@ g:latex_to_unicode_eager
271306
pressing <Tab> again performs the substitution.
272307

273308
This variable can be set at any time, changes will immediately
274-
take effect. When |g:latex_to_unicode_suggestions| is 0,
309+
take effect. When |g:latex_to_unicode_suggestions| is `0`,
275310
this setting has no effect (it's like if it was always on).
276311

277312
*g:latex_to_unicode_auto*
278313
g:latex_to_unicode_auto
279314

280315
Determines whether to activate LaTeX-to-Unicode substitution
281316
on the fly as you type (in |Insert| mode), see
282-
|julia-vim-L2U-as-you-type|. If unspecified, it is 0 (off).
317+
|julia-vim-L2U-as-you-type|. If unspecified, it is `0` (off).
283318
You can enable the feature by default by inserting the line
284319
>
285320
let g:latex_to_unicode_auto = 1
@@ -288,6 +323,23 @@ g:latex_to_unicode_auto
288323
moment while editing, but you need to invoke
289324
|LaTeXtoUnicode#Init()| for the change to take effect.
290325

326+
327+
*g:latex_to_unicode_keymap*
328+
g:latex_to_unicode_keymap
329+
330+
Determines whether to activate the |keymap|-based
331+
LaTeX-to-Unicode substitutions, see |julia-vim-L2U-keymap|.
332+
If unspecified, it is `0` (off). You can enable the feature by
333+
default by inserting the line
334+
>
335+
let g:latex_to_unicode_keymap = 1
336+
<
337+
in your |.vimrc| file. You can change this setting at any
338+
moment while editing, but you need to invoke
339+
|LaTeXtoUnicode#Init()| for the change to take effect.
340+
It's advisable to disable |g:latex_to_unicode_tab| and
341+
|g:latex_to_unicde_auto| if you use this.
342+
291343
*g:latex_to_unicode_file_types*
292344
g:latex_to_unicode_file_types
293345

keymap/latex2unicode_utf-8.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" This file is autogenerated from the script 'generate_L2U_keymap.jl'
22
" The full script can be found in the comments at the bottom of this file
3-
" The symbols are based on Julia version 1.0.2-pre.0
3+
" The symbols are based on Julia version 1.1.0-DEV.695
44

55
scriptencoding utf-8
66

0 commit comments

Comments
 (0)