Skip to content

s417-lama/carbonpaper.vim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

carbonpaper.vim

Highlight LaTeX code in your favorite colorscheme of Vim!

carbonpaper.vim transfers code selected in Vim into LaTeX listings, preserving the colorscheme in Vim. By using carbonpaper.vim, syntax highlighting becomes independent of LaTeX, so you can get beautifully highlighted code with your favorite vim colorscheme.

The example below shows the transformation of Elixir code, which is not supported by LaTeX.

default_all

(The colorscheme of the above is hybrid)

Also, you can use different colorschemes or light theme that well matches LaTeX typesetting only when transferring code. See below.

Getting Started

Installation

Please follow the instructions of the plugin manager you use. If your plugin manager is dein.vim, just add

call dein#add('s417-lama/carbonpaper.vim')

Overview

  1. Select code you want to transfer in visual mode.
  2. Execute command :CarbonPaper and save an output file.
  3. Include the generated file in LaTeX (using \input command).
  4. Compile the LaTeX code!

You can select a part of the code by using visual block mode in Vim. Also, a colorscheme and background can be configured as shown below.

papercolor_part

For reference, the configuration was:

let g:carbonpaper#colorscheme          = 'PaperColor'
let g:carbonpaper#background           = 'light'
let g:carbonpaper#set_background_color = 0
let g:carbonpaper#highlight_bold       = 1

Insert code into LaTeX

If the name of the output file you saved is hoge.tex, insert the TeX code below where you want to insert the transferred code.

\input hoge.tex

(Assuming that hoge.tex is located at the same directory as the LaTeX code.)

The required packages are:

\usepackage{listings}
\usepackage{xcolor}

Since font in Vim is not transferred, font in listings is also important. I recommend to use inconsolata font.

The LaTeX code used in the demo is samples/demo/demo.tex. Please consult it if you need more information. The generated PDF is samples/demo/demo.pdf.

Configuration

colorscheme

If you want to use another colorscheme only when transferring into LaTeX, you can specify it.

let g:carbonpaper#colorscheme = 'PaperColor'

background

background option in Vim (light or dark). You can change it only when transferring.

let g:carbonpaper#background = 'light'

set_background_color, set_foreground_color

Whether or not to set the normal bg/fg color in listings. If you want to use the default normal color specified in your \lstset, set

let g:carbonpaper#set_background_color = 0
let g:carbonpaper#set_foreground_color = 0

(default: 1)

highlight_bold

All colored text becomes bold (\bfseries in LaTeX) for visibility.

let g:carbonpaper#highlight_bold = 1

(default: 0)

Documentation

You can see detailed information by entering

:h carbonpaper

in Vim.

The same document can be also seen in samples/doc/doc.pdf. This document is generated from the help file by carbonpaper.vim and compiled by LaTeX. The colorscheme is PaperColor.

License

MIT License. Copyright (c) 2018-2019 Shumpei Shiina

About

Transfer code to LaTeX with your colorscheme in Vim

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published