Alberto Álvarez

Posts tagged "latex":

11 Apr 2020

pdf-tools as the default PDF viewer in Emacs

I got tired of Emacs opening a .pdf file using an external viewer program. To solve this, I decided to go with PDF Tools for Emacs, which renders the file in a buffer giving you more control and keeping everything inside the editor. To do this, I added the following lines to my .emacs file:

(use-package pdf-tools
   :pin manual
   :config
   (pdf-tools-install)
   (setq-default pdf-view-display-size 'fit-width)
   (define-key pdf-view-mode-map (kbd "C-s") 'isearch-forward)
   :custom
   (pdf-annot-activate-created-annotations t "automatically annotate highlights"))

This would just make PDF Tools available for Emacs but wouldn't make it a default. To do this, I added a few more lines of code:

(setq TeX-view-program-selection '((output-pdf "PDF Tools"))
      TeX-view-program-list '(("PDF Tools" TeX-pdf-tools-sync-view))
      TeX-source-correlate-start-server t)

(add-hook 'TeX-after-compilation-finished-functions
	  #'TeX-revert-document-buffer)

PDF Tools is an Emacs support library for PDF files and it has a lot of features like annotations, I just use it for .pdf visualisation but it has a bunch of features that are worth exploring.

Something important is that this library doesn't play well with Emacs linum-mode. The following lines of code will deactivate this mode when rendering the .pdf:

(add-hook 'pdf-view-mode-hook (lambda() (linum-mode -1)))

This simple change allows me to open all my PDFs in emacs while doing research. This plays really well with Emacs extensions like org-ref and org-roam.

Tags: latex emacs
11 Apr 2020

Exporting references using aux2bib

A useful command when working with a LaTex document is aux2bib. Sometimes, we use a global reference file, where we have all of our references available, and from that file we just select the ones that would be included in our LaTex document. The downside is that this global bibtex file could have hundreds or thousands of references that are not included in the final .pdf file produced by LaTex. To generate a .bib file that includes only the references in the document, we can call aux2bib, using a the .aux file that results from the LaTex compilation process. To have access to aux2bib, we have to install the bib2html package. We can do this in Ubuntu by typing the following command in the terminal:

$ sudo apt install bibtex2html

Once installed, we just go to the folder where the .aux file is located and we call

$ aux2bib myauxfile.aux > references.bib

where myauxfile.aux is your .aux file and references.bib is the resulting bibtex file with the references used in your LaTex document. You could use any name for this file, references.bib in this case is just an example.

Tags: latex
Other posts
alberto.am by Alberto Álvarez is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.