Lecture 2: BibTeX and Vim
Table of Contents
- 1. BibTeX
- 2. Code Ace Jumper (extension)
- 3. Vim (extension)
- 3.1. Overview
- 3.2. Installation
- 3.3. Changing modes
- 3.4. Movements (Normal Mode)
- 3.5. Editing (Normal Mode)
- 3.6. Visual Mode
- 3.7. Finding a letter (Normal Mode)
- 3.8. Finding a word (Normal Mode)
- 3.9. Other useful commands (Normal Mode)
- 3.10. Useful combos
- 3.11. Registers
- 3.12. Mark positions
- 3.13. Dot: Repeat the previous command.
- 3.14. Macros
- 3.15. More advanced commands: i and s
1 BibTeX
1.1 Overview
- BibTeX is a program used for generating references.
- First you need a BibTeX file.
Then you need to have the following two lines in you tex file:
\bibliographystyle{STYLE} \bibliography{BIBFILE}
STYLE
can beabbrv
,alpha
,plain
, etc.BIBFILE
is the location of your BibTeX, for example, something like this:/Users/jangsookim/bibtex/ref.bib
- All exercises in this section will use the tex file and the bib file in "bib-exercise" folder in this file.
1.1.1 Exercise
- Compile the tex file in "bib-exercise" folder.
At the end of the tex file there is a line as follows.
\bibliography{./ref.bib}
Change the relative path
./ref.bib
to the absolute path.- Check if the references are compiled as before.
1.2 Add a citation in VS Code
- Similarly to
\ref{}
if you type\cite{
all available bib items appear. - By clicking the arrow at the right you can see the content of each item.
- If you type letters it shows all items having those letters in authors, titles, journals, year, etc.
1.3 NatBib package
- NatBib package shows citations using author names and years instead of numbers.
- To use this package add
\usepackage{natbib}
in your tex file. - NatBib package has styles like these.
plainnat
abbrvnat
- See LaTeX/Bibliography Management for more information.
- Exercise: Try the above two styles in the tex file.
1.4 Entries in BibTeX file
A BibTeX file has entries like this:
@article{Bressoud1979, title={A generalization of the {R}ogers-{R}amanujan identities for all moduli}, author={Bressoud, David M}, journal={Journal of Combinatorial Theory, Series A}, volume={27}, number={1}, pages={64--68}, year={1979}, }
- To cite this paper you can type
\cite{Bressoud1979}
in your tex file. - Note that in the title you must use
{ }
for capital letters as above.
1.4.1 Exercise
- Add the previous entry in the
ref.bib
file. - Cite this paper in the tex file and compile it.
- See what happens if you write "Rogers-Ramanujan" instead of "{R}ogers-{R}amanujan".
1.5 arXiv papers
arXiv papers or preprints can be added like this.
@misc{kim20:jacob_flagged, author = {Jang Soo Kim}, title = {{Jacobi--Trudi formulas for flagged refined dual stable Grothendieck polynomials}}, howpublished = {arXiv:2008.12000v2} }
1.6 BibTeX entries from Google Scholar
- Search the paper you want to cite in Google Scholar. https://scholar.google.com/
- Google Scholar will show a thumbnail for that paper.
- Click
"
at the bottom of the thumbnail. - Click the BibTeX icon at the bottom.
- You can copy the text into you BibTeX file.
- There are other data base systems such as MathSciNet (but you need a subscription).
1.6.1 Exercise
Add a bib entry to
ref.bib
for the following paper using Google Scholar.S. Eliahou, Wilf’s conjecture and Macaulay’s theorem, J. Eur. Math. Soc. (JEMS), 20(9):2105–2129, 2018.
- Cite this paper in the tex file and compile it.
- Repeat 1 and 2 using MathSciNet.
1.7 JabRef
- JabRef is a free BibTeX Manager.
- Download here: http://www.jabref.org/
- JabRef is useful when your BibTeX file has many entries.
- Using JabRef you can add a new entry directly from "Web search" at the bottom left corner.
- I couldn't find any BibTeX managers in VS Code extensions. Let me know if you find one.
- BibDesk is also a good BibTeX manager but only for Mac.
1.7.1 Exercise
Add the following paper to
ref.bib
.P. Langevin, Calculs de Certaines Sommes de Gauss, J. Number Theory 32, 59–64, (1997)
- Cite these papers in the tex file and compile it.
Repeat 1 and 2 with the following arXiv paper.
Florence Maas-Gariépy and Rebecca Patrias, Set-valued domino tableaux and shifted set-valued domino tableaux, arXiv:2011.12493
- Note: If you use JabRef, you may have to change the bibitem type from
@Article
to@Misc
and add a new entryhowpublished
.
- Note: If you use JabRef, you may have to change the bibitem type from
1.8 bbl file
- If you compile bibtex, it will generate a bbl file
TEXFILENAME.bbl
, whereTEXFILENAME
is your tex filename. - This file contains all bibitems you need in your tex file.
- You can copy everything in this file and paste it at the end of your tex file.
- After this you no longer need your BibTeX file.
- This may be helpful if you want to have a single stand-alone tex file.
1.8.1 Exercise
- Edit the tex file so that it does not need the bib file.
2 Code Ace Jumper (extension)
2.1 Overview
- Code Ace Jumper is an extension that allows you to jump around your file.
- How to use:
- Execute "AceJump: Jump".
- Type a letter, say
d
, and it will assign a letter (or two or more) to each word starting withd
. - Type the letter assigned to the word that you want to move.
- There are three more commands like this.
- First, you need to assign keyboard shortcuts for these commands.
2.2 Add Keyboard shortcuts
- CP \(\rightarrow\) Preferences: Open Keyboard Shortcuts
- Search "ace jump".
- You can assign a keyboard shortcut by double clicking each command. For
example,
- AceJump: Jump \(\rightarrow\) CMD+J J
- AceJump: Line \(\rightarrow\) CMD+J L
- AceJump: MultiChar \(\rightarrow\) CMD+J M
- AceJump: Selection \(\rightarrow\) CMD+J S
2.3 Change some options
2.3.1 Redefine "words"
- We want to make the
f
in\frac
or in$f$
as the start of a word. - CP \(\rightarrow\) Preferences: Open Settings (UI). (or
CMD+,
for a shortcut) - Search "Ace Jump > Finder: Pattern".
Add
\\$
at the end, just before]
in[,-.{_("'<\[ ]
so that it looks like this:
[,-.{_("'<\[ \\$]
2.3.2 Change the background color
- Enter "yellow" in "Ace Jump > Placeholder: Background Color".
2.3.3 Change the scroll mode
- Set "none" in "Ace Jump > Scroll:Mode".
3 Vim (extension)
3.1 Overview
- Vim is a modal editor meaning that it has several modes.
- Normal mode: used for editor commands
- Insert mode: used for inserting text
- Command-line mode: used for doing some commands
- Vim Extension allows us to use Vim commands inside VS Code.
- Vim graphical cheat sheet
3.2 Installation
- First you need to install Vim using "Extensions" icon as before.
- Once you have Vim installed, you can use Vim commands immediately.
- You can disable Vim as follows.
- Click Vim in "Extensions".
- Click "Disable".
3.3 Changing modes
key | command |
---|---|
i | Change to Insert Mode at cursor |
a | Change to Insert Mode after cursor |
ESC | Change to Normal Mode |
: | Change to Command-line Mode |
3.4 Movements (Normal Mode)
key | command |
---|---|
h, j, k, l | left, down, up, right |
w | next word |
b | previous word |
CTRL+f | page forward |
CTRL+b | page backward |
- Typing
n
will repeat the following command n times. - For example,
4w
is equivalent towwww
. - You can still use the arrow keys, but it's not recommended.
3.5 Editing (Normal Mode)
key | command |
---|---|
y | yank something |
d | delete something |
p | paste after |
P | paste before |
x | delete letter at cursor |
- Deleted text is always copied in clipboard.
- You can make a sentence using these.
yy
: yank linedd
: delete linedw
: delete word
3.6 Visual Mode
key | command |
---|---|
v | Change to Visual Mode |
V | Change to Visual Mode (line-wise) |
- Visual Mode highlights a region.
- In Visual Mode,
y
yanks the content in the selected region. - In Visual Mode,
d
deletes the content in the selected region.
3.7 Finding a letter (Normal Mode)
key | command |
---|---|
f \(\star\) | Move cursor to \(\star\) in current line. |
t \(\star\) | Move cursor before \(\star\) in current line. |
F \(\star\) | Similar to "f" but backward. |
T \(\star\) | Similar to "t" but backward. |
; | Repeat the previous finding command. |
- \(\star\) is a letter you need to type after
f
,t
, etc.
3.8 Finding a word (Normal Mode)
key | command |
---|---|
/ |
Find a word. |
n | Find the next word. |
N | Find the previous word. |
/abc ENTER
will move the cursor after the first occurrence of the wordabc
.n
will find the next occurrence of the word.N
will find the previous occurrence of the word.
3.9 Other useful commands (Normal Mode)
key | command |
---|---|
u | Undo |
CTRL+r | Redo |
0 | beginning of line |
$ | end of line |
( | beginning of sentence |
) | end of sentence |
gg | beginning of the file |
G | end of the file |
zz | scroll cursor to center |
3.10 Useful combos
yf$
: If you are at the beginning of an inline math mode$
, thenyf$
can copy the whole math expression.y)
: Copy the sentence (from the location of cursor).dt.
: This will delete up to the period.xp
: This will swap two letters.Selecting a whole section: (cursor at \section{ABC})
V / \\section Enter k
- Selecting a whole file:
gg V G
3.11 Registers
- You can store something in a register.
- The easiest way is as follows:
- Select a region that you want to register.
- Type
ay
, wherea
can be any letter. - This will register the content of the region at register
a
. - Type
ap
oraP
to insert the content at registera
.
- To view the registers type the following.
:reg ENTER
3.12 Mark positions
- You can mark the current position for future use.
ma
marks the current position bya
, wherea
can be any letter.- Typing
`a
send you back to the position marked bya
.
- It's helpful to mark the position where macros are defined.
3.13 Dot: Repeat the previous command.
.
repeats the previously performed command.- For example,
dd
deletes the line at cursor. Pressing.
will delete another line. - When used carefully, this dot command can be very effective.
- More complicated tasks can be done by macros.
3.14 Macros
qa
followed byq
records all your commands performed between them ata
.@a
repeats the commands recorded ata
.@@
runs the previously performed macro.In order to write more complicated macros, you need to know more Vim commands, for example,
key command c Change something e end of word 0 beginning of line $ end of line
3.14.1 Example
We want to insert
&
before each=
below.\begin{align*} a = b,\\ a+a = b+b,\\ a+a+a = b+b+b,\\ a+a+a+a = b+b+b+b. \end{align*}
- We can do this using a macro like this.
- Locate your cursor at the beginning of line 2.
- (In Normal Mode) Press
qa
. - Type
f = i & ESC k 0
andq
. - Type
@a
and then@@
twice.
3.14.2 Exercises
Replace each pair
[ ]
by( )
using a macro (you may use one macro many times).\begin{align*} a[x] = b[x],\\ a[x]+a[y] = b[x]+b[y],\\ a[x]+a[y]+a[z] = b[x]+b[y]+b[z],\\ a[x]+a[y]+a[z]+a[w] = b[x]+b[y]+b[z]+b[w]. \end{align*}
- Replace each letter in parentheses by its capital letter. (Hint: Try
~
on a letter.)
3.15 More advanced commands: i and s
i
means "inner" ands
means "surrounding".- Using these keys you can create a sentence like this.
yiw
: yank inner word- This is similar to
yw
(yank word), but the cursor doesn't have to be at the beginning of a word. diw
andciw
work similarly with deleting and changing.
- This is similar to
ysiw)
: insert ( ) surrounding inner wordysiw$
: insert $ $ surrounding inner wordysiW$
: insert $ $ surrounding inner WORD (WORD means a maximal string without a space)