[][src]Function syntect::util::as_latex_escaped

pub fn as_latex_escaped(v: &[(Style, &str)]) -> String

Formats the styled fragments using LaTeX textcolor directive.

Usage is similar to the as_24_bit_terminal_escaped function:

use syntect::easy::HighlightLines;
use syntect::parsing::SyntaxSet;
use syntect::highlighting::{ThemeSet,Style};
use syntect::util::{as_latex_escaped,LinesWithEndings};

// Load these once at the start of your program
let ps = SyntaxSet::load_defaults_newlines();
let ts = ThemeSet::load_defaults();

let syntax = ps.find_syntax_by_extension("rs").unwrap();
let s = "pub struct Wow { hi: u64 }\nfn blah() -> u64 {}\n";

let mut h = HighlightLines::new(syntax, &ts.themes["InspiredGitHub"]);
for line in LinesWithEndings::from(s) { // LinesWithEndings enables use of newlines mode
    let ranges: Vec<(Style, &str)> = h.highlight(line, &ps);
    let escaped = as_latex_escaped(&ranges[..]);
    println!("{}", escaped);
}

Returned content is intended to be placed inside a fancyvrb Verbatim environment:

\usepackage{fancyvrb}
\usepackage{xcolor}
% ...
% enable comma-separated arguments inside \textcolor
\makeatletter
\def\verbatim@nolig@list{\do\`\do\<\do\>\do\'\do\-}
\makeatother
% ...
\begin{Verbatim}[commandchars=\\\{\}]
% content goes here
\end{Verbatim}

Background color is ignored.