Lecture 2: BibTeX and Vim

Jang Soo Kim

Created: 2020-12-04 Fri 13:22

BibTeX

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 be abbrv, 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.

Exercise

  1. Compile the tex file in "bib-exercise" folder.
  2. 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.

  3. Check if the references are compiled as before.

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.

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.

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.

Exercise

  1. Add the previous entry in the ref.bib file.
  2. Cite this paper in the tex file and compile it.
  3. See what happens if you write "Rogers-Ramanujan" instead of "{R}ogers-{R}amanujan".

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}
    }
    

BibTeX entries from Google Scholar

  1. Search the paper you want to cite in Google Scholar. https://scholar.google.com/
  2. Google Scholar will show a thumbnail for that paper.
  3. Click " at the bottom of the thumbnail.
  4. Click the BibTeX icon at the bottom.
  5. You can copy the text into you BibTeX file.
  6. There are other data base systems such as MathSciNet (but you need a subscription).

Exercise

  1. 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.
    
  2. Cite this paper in the tex file and compile it.
  3. Repeat 1 and 2 using MathSciNet.

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.

Exercise

  1. Add the following paper to ref.bib.

    P. Langevin, Calculs de Certaines Sommes de Gauss, 
    J. Number Theory 32, 59–64, (1997)
    
  2. Cite these papers in the tex file and compile it.
  3. 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 entry howpublished.

bbl file

  • If you compile bibtex, it will generate a bbl file TEXFILENAME.bbl, where TEXFILENAME 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.

Exercise

  • Edit the tex file so that it does not need the bib file.

Code Ace Jumper (extension)

Overview

  • Code Ace Jumper is an extension that allows you to jump around your file.
  • How to use:
    1. Execute "AceJump: Jump".
    2. Type a letter, say d, and it will assign a letter (or two or more) to each word starting with d.
    3. 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.

Add Keyboard shortcuts

  1. CP \(\rightarrow\) Preferences: Open Keyboard Shortcuts
  2. Search "ace jump".
  3. 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

Change some options

Redefine "words"

  1. We want to make the f in \frac or in $f$ as the start of a word.
  2. CP \(\rightarrow\) Preferences: Open Settings (UI). (or CMD+, for a shortcut)
  3. Search "Ace Jump > Finder: Pattern".
  4. Add \\$ at the end, just before ] in

    [,-.{_("'<\[ ]
    

    so that it looks like this:

    [,-.{_("'<\[ \\$]
    

Change the background color

  • Enter "yellow" in "Ace Jump > Placeholder: Background Color".

Change the scroll mode

  • Set "none" in "Ace Jump > Scroll:Mode".

Vim (extension)

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

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.
    1. Click Vim in "Extensions".
    2. Click "Disable".

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

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 to wwww.
  • You can still use the arrow keys, but it's not recommended.

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 line
  • dd : delete line
  • dw : delete word

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.

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.

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 word abc.
  • n will find the next occurrence of the word.
  • N will find the previous occurrence of the word.

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

Useful combos

  • yf$: If you are at the beginning of an inline math mode $, then yf$ 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

Registers

  • You can store something in a register.
  • The easiest way is as follows:
    1. Select a region that you want to register.
    2. Type ay, where a can be any letter.
    3. This will register the content of the region at register a.
    4. Type ap or aP to insert the content at register a.
  • To view the registers type the following.
    :reg ENTER

Mark positions

  • You can mark the current position for future use.
    1. ma marks the current position by a, where a can be any letter.
    2. Typing `a send you back to the position marked by a.
  • It's helpful to mark the position where macros are defined.

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.

Macros

  • qa followed by q records all your commands performed between them at a.
  • @a repeats the commands recorded at a.
  • @@ 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

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.
    1. Locate your cursor at the beginning of line 2.
    2. (In Normal Mode) Press qa.
    3. Type f = i & ESC k 0 and q.
    4. Type @a and then @@ twice.

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.)

More advanced commands: i and s

  • i means "inner" and s 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 and ciw work similarly with deleting and changing.
  • ysiw): insert ( ) surrounding inner word
  • ysiw$: insert $ $ surrounding inner word
  • ysiW$: insert $ $ surrounding inner WORD (WORD means a maximal string without a space)