pub(crate) mod math;
mod text;
mod vietnamese;
use super::markdown::{linked_anchors, strip_label};
use super::{
CAP_LABEL, Equations, HtmlOptions, ImageStore, Mode, PageImage, caption_first, code, code_run, doc_title,
equation_math, float_class, heading_tag, is_abstract_text, is_scene_break, plain, stray_equation_number,
};
use crate::analysis::pipeline::Analysis;
use crate::backend::PdfFile;
use crate::model::{Block, BlockKind, Document, FloatKind, ImageSpec, MONO, Span, Table, TableCell};
use crate::render::Pictures;
use math::latex;
use std::cell::RefCell;
use std::collections::BTreeSet;
use text::{LAST_LATIN, LATIN_GAPS, Text, escape, label};
const PREAMBLE: &str = include_str!("preamble.tex");
const MAX_LIST_NESTING: u8 = 3;
const T1_FONTENC: &str = "\\usepackage[T1]{fontenc}";
const T5_FONTENC: &str = "\\usepackage[T5,T1]{fontenc}";
const CONTENTS_INDENT_EM: f32 = 1.5;
const REFERENCE_INDENT: &str = "1.5em";
const RAGGED_MONO_RATIO: f32 = 0.5;
const AUTHOR_CARD_MAX_CHARS: usize = 60;
const AUTHOR_GAP: &str = "2em";
const TAB_SPACES: &str = " ";
#[derive(Debug, Clone)]
pub struct LatexOptions {
pub asset_dir: String,
pub scale: f32,
pub jobs: usize,
pub equations: Equations,
}
impl Default for LatexOptions {
fn default() -> Self {
Self {
asset_dir: "images".into(),
scale: 3.0,
jobs: 0,
equations: Equations::MathMl,
}
}
}
pub struct LatexOutput {
pub latex: String,
pub files: Vec<(String, Vec<u8>)>,
}
pub fn render_latex(analysis: &Analysis, pdf: Option<&PdfFile>, opts: &LatexOptions) -> LatexOutput {
let html_opts = HtmlOptions {
mode: Mode::Friendly,
inline_images: false,
asset_dir: tex_path(&opts.asset_dir),
scale: opts.scale,
page_image: PageImage::Svg,
jobs: opts.jobs,
embed_fonts: false,
equations: opts.equations,
};
let mut images = ImageStore {
opts: &html_opts,
jobs: Vec::new(),
vector: false,
};
let doc = &analysis.doc;
let anchors = linked_anchors(doc);
let mut writer = Writer {
opts,
text: Text {
anchors: &anchors,
math: opts.equations == Equations::MathMl,
table_notes: RefCell::default(),
},
images: &mut images,
out: String::new(),
group: Group::None,
item_open: false,
nested: 0,
after_text: false,
};
writer.write(doc);
let body = writer.out.trim_end().to_string();
let out = images.finish(Pictures::new(pdf, &analysis.doc), body);
LatexOutput {
latex: document(doc, &out.html),
files: out.files,
}
}
fn document(doc: &Document, body: &str) -> String {
let title = escape(&doc_title(doc));
let (vietnamese, unknown): (Vec<char>, Vec<char>) = unknown_chars(&title, body)
.into_iter()
.partition(|&ch| vietnamese::t5_letter(ch).is_some());
let mut out = if vietnamese.is_empty() {
String::from(PREAMBLE)
} else {
PREAMBLE.replacen(T1_FONTENC, T5_FONTENC, 1)
};
if doc.pages.is_empty() {
out = out.replacen("Converted from a PDF", "Converted from a Word document", 1);
}
if !vietnamese.is_empty() {
out.push_str(&format!(
"% Vietnamese letters: pdfLaTeX sets them in the T5 encoding (vntex).\n\\ifPDFTeX\n \\newcommand{{{cmd}}}[1]{{{{\\fontencoding{{T5}}\\selectfont#1}}}}\n",
cmd = vietnamese::T5_COMMAND
));
for ch in vietnamese {
let letter = vietnamese::t5_letter(ch).expect("partitioned on t5_letter");
out.push_str(&format!(
" \\DeclareUnicodeCharacter{{{:04X}}}{{{}{{{letter}}}}}\n",
u32::from(ch),
vietnamese::T5_COMMAND
));
}
out.push_str("\\fi\n");
}
if !unknown.is_empty() {
out.push_str("% Characters that the fonts of pdfLaTeX do not have.\n\\ifPDFTeX\n");
for ch in unknown {
out.push_str(&format!(
" \\DeclareUnicodeCharacter{{{:04X}}}{{\\kakemonomissing}}\n",
u32::from(ch)
));
}
out.push_str("\\fi\n");
}
out.push_str(&format!(
"\\hypersetup{{pdftitle={{{title}}}}}\n\n\\begin{{document}}\n\n"
));
out.push_str(body);
out.push_str("\n\n\\end{document}\n");
out
}
fn unknown_chars(title: &str, body: &str) -> BTreeSet<char> {
title
.chars()
.chain(body.chars())
.filter(|&ch| !ch.is_ascii() && (ch > LAST_LATIN || LATIN_GAPS.contains(&ch)))
.collect()
}
fn tex_path(dir: &str) -> String {
dir.trim_end_matches(['/', '\\'])
.chars()
.map(|ch| {
if ch.is_ascii_alphanumeric() || matches!(ch, '.' | '_' | '-' | '/') {
ch
} else {
'_'
}
})
.collect()
}
#[derive(PartialEq, Clone, Copy)]
enum Group {
None,
List,
Abstract,
}
impl Group {
fn of(block: &Block, current: Self) -> Self {
match &block.kind {
BlockKind::ListItem { .. } | BlockKind::ListContinuation => Self::List,
BlockKind::Paragraph { in_abstract: true } => Self::Abstract,
BlockKind::Equation { .. } if current == Self::Abstract => current,
_ => Self::None,
}
}
fn environment(self) -> Option<&'static str> {
match self {
Self::None => None,
Self::List => Some("itemize"),
Self::Abstract => Some("abstract"),
}
}
}
struct Writer<'a, 'r> {
opts: &'a LatexOptions,
text: Text<'a>,
images: &'a mut ImageStore<'r>,
out: String,
group: Group,
item_open: bool,
nested: u8,
after_text: bool,
}
impl Writer<'_, '_> {
fn write(&mut self, doc: &Document) {
let blocks: Vec<&Block> = doc.blocks.iter().collect();
let mut idx = 0;
let mut after_front = false;
while idx < blocks.len() {
let block = blocks[idx];
if !after_front && !matches!(block.kind, BlockKind::Title | BlockKind::Authors | BlockKind::Note) {
self.arxiv_link(doc);
after_front = true;
}
if let Some(end) = code_run(&blocks, idx) {
self.set_group(Group::None);
self.anchor(block);
self.verbatim(&code::listing_lines(&blocks[idx..end]));
idx = end;
continue;
}
self.set_group(Group::of(block, self.group));
match &block.kind {
BlockKind::Title => {
idx = self.title(doc, &blocks, idx);
continue;
}
BlockKind::Authors => {
idx = self.authors(&blocks, idx);
continue;
}
BlockKind::Heading { .. }
if is_abstract_text(&block.spans)
&& blocks
.get(idx + 1)
.is_some_and(|next| matches!(next.kind, BlockKind::Paragraph { in_abstract: true })) =>
{
self.anchor(block);
idx += 1;
continue;
}
BlockKind::Equation { image, number: None } => {
if let Some(number) = blocks.get(idx + 1).and_then(|next| stray_equation_number(next)) {
self.equation(block, image.as_ref(), Some(&number));
idx += 2;
continue;
}
}
_ => {}
}
self.block(block);
idx += 1;
}
if !after_front {
self.arxiv_link(doc);
}
self.set_group(Group::None);
}
fn set_group(&mut self, group: Group) {
if group == self.group {
return;
}
self.nest(0);
if let Some(env) = self.group.environment() {
self.paragraph(&format!("\\end{{{env}}}"));
}
if let Some(env) = group.environment() {
self.paragraph(&format!("\\begin{{{env}}}"));
}
self.group = group;
self.item_open = false;
}
fn block(&mut self, block: &Block) {
if !matches!(
block.kind,
BlockKind::ListItem { .. } | BlockKind::ListContinuation | BlockKind::Equation { .. }
) {
self.anchor(block);
}
match &block.kind {
BlockKind::Title => self.title_text(&self.text.spans(&block.spans)),
BlockKind::Authors => {
self.authors(std::slice::from_ref(&block), 0);
}
BlockKind::Note => self.text_paragraph(&block.spans),
BlockKind::Heading { level } => self.heading(block, *level),
BlockKind::Paragraph { .. } if is_scene_break(&block.spans) => {
self.paragraph("\\begin{center}\n* * *\n\\end{center}");
}
BlockKind::Paragraph { .. } => self.text_paragraph(&block.spans),
BlockKind::ListItem { marker, level } => self.list_item(block, marker.as_deref(), *level),
BlockKind::ListContinuation => self.list_continuation(block),
BlockKind::Reference { .. } => {
let text = self.text.spans(&block.spans);
if !text.is_empty() {
self.paragraph(&format!(
"{{\\small\\noindent\\hangindent={REFERENCE_INDENT}\\relax {text}\\par}}"
));
}
}
BlockKind::Footnote { marker } => self.footnote(block, marker),
BlockKind::Equation { image, number } => self.equation(block, image.as_ref(), number.as_deref()),
BlockKind::Figure { kind, image, .. } => self.figure(block, *kind, image.as_ref()),
BlockKind::ContentsEntry { level, page } => self.contents_entry(block, *level, page),
BlockKind::Code => {
let lines: Vec<String> = block
.rows
.iter()
.map(|row| row.iter().map(|span| span.text.as_str()).collect())
.collect();
self.verbatim(&lines);
}
}
}
fn paragraph(&mut self, text: &str) {
self.out.push_str(text);
self.out.push_str("\n\n");
self.after_text = false;
}
fn text_paragraph(&mut self, spans: &[Span]) {
let text = self.text.spans(spans);
if text.is_empty() {
return;
}
if mono_ratio(spans) >= RAGGED_MONO_RATIO {
self.paragraph(&format!("{{\\raggedright {text}\\par}}"));
} else {
self.paragraph(&text);
}
self.after_text = true;
}
fn anchor_label(&self, block: &Block) -> String {
block
.anchor
.as_deref()
.filter(|anchor| self.text.anchors.contains(*anchor))
.map(|anchor| format!("\\phantomsection\\label{{{}}}", label(anchor)))
.unwrap_or_default()
}
fn anchor(&mut self, block: &Block) {
let label = self.anchor_label(block);
if !label.is_empty() {
self.out.push_str(&label);
self.out.push('\n');
}
}
fn arxiv_link(&mut self, doc: &Document) {
if let Some(id) = &doc.meta.arxiv_id {
let link = format!("\\href{{https://arxiv.org/abs/{}}}{{arXiv:{}}}", escape(id), escape(id));
self.paragraph(&format!("\\begin{{center}}\n{link}\n\\end{{center}}"));
}
}
fn title(&mut self, doc: &Document, blocks: &[&Block], start: usize) -> usize {
let end = start
+ blocks[start..]
.iter()
.take_while(|block| matches!(block.kind, BlockKind::Title))
.count();
let mut spans: Vec<Span> = Vec::new();
for block in &blocks[start..end] {
self.anchor(block);
if !spans.is_empty() {
spans.push(Span::plain(" "));
}
spans.extend(block.spans.iter().cloned());
}
let text = self.text.spans(&spans);
if text.is_empty() {
self.title_text(&escape(&doc_title(doc)));
} else {
self.title_text(&text);
}
end
}
fn title_text(&mut self, text: &str) {
self.paragraph(&format!(
"\\begin{{center}}\n{{\\LARGE\\bfseries {text}\\par}}\n\\end{{center}}"
));
}
fn authors(&mut self, blocks: &[&Block], start: usize) -> usize {
let end = start
+ blocks[start..]
.iter()
.take_while(|block| matches!(block.kind, BlockKind::Authors))
.count();
let mut cards: Vec<String> = Vec::new();
for block in &blocks[start..end] {
self.anchor(block);
let lines = self.author_lines(block);
if lines.is_empty() {
continue;
}
if author_rows(block)
.iter()
.all(|row| plain(row).chars().count() <= AUTHOR_CARD_MAX_CHARS)
{
cards.push(format!(
"\\begin{{tabular}}[t]{{@{{}}c@{{}}}}\n{}\n\\end{{tabular}}",
lines.join("\\\\\n")
));
} else {
self.author_cards(&mut cards);
self.paragraph(&format!("\\begin{{center}}\n{}\n\\end{{center}}", lines.join("\\\\\n")));
}
}
self.author_cards(&mut cards);
end
}
fn author_cards(&mut self, cards: &mut Vec<String>) {
if !cards.is_empty() {
let row = cards.join(&format!("\n\\hspace{{{AUTHOR_GAP}}}\n"));
self.paragraph(&format!("\\begin{{center}}\n{row}\n\\end{{center}}"));
cards.clear();
}
}
fn author_lines(&self, block: &Block) -> Vec<String> {
author_rows(block)
.iter()
.enumerate()
.map(|(i, row)| {
let text = self.text.spans(row);
if i == 0 && !text.is_empty() && !text.starts_with("\\textbf{") {
format!("\\textbf{{{text}}}")
} else {
protect_start(&text)
}
})
.filter(|text| !text.is_empty())
.collect()
}
fn heading(&mut self, block: &Block, level: u8) {
let text = self.text.spans(&block.spans);
if text.is_empty() {
return;
}
let command = match heading_tag(level) {
"h2" => "section",
"h3" => "subsection",
"h4" => "subsubsection",
_ => "paragraph",
};
self.paragraph(&format!("\\{command}*{{{text}}}"));
}
fn list_item(&mut self, block: &Block, marker: Option<&str>, level: u8) {
self.nest(level.min(MAX_LIST_NESTING));
let rest = marker.and_then(|marker| strip_label(&block.spans, marker));
let item = match (marker, &rest) {
(Some(marker), Some(_)) => format!("\\item[{{{}}}]", escape(marker)),
_ => "\\item".to_string(),
};
let text = self.text.spans(rest.as_deref().unwrap_or(&block.spans));
let text = if rest.is_some() { text } else { protect_start(&text) };
let label = self.anchor_label(block);
self.paragraph(format!("{item} {label}{text}").trim_end());
self.item_open = true;
}
fn nest(&mut self, level: u8) {
while self.nested > level {
self.paragraph("\\end{itemize}");
self.nested -= 1;
self.item_open = true;
}
while self.nested < level {
if !self.item_open {
self.out.push_str("\\item[]\n");
}
self.paragraph("\\begin{itemize}");
self.nested += 1;
self.item_open = false;
}
}
fn list_continuation(&mut self, block: &Block) {
if !self.item_open {
self.out.push_str("\\item[]\n");
self.item_open = true;
}
let text = self.text.spans(&block.spans);
let label = self.anchor_label(block);
if !text.is_empty() || !label.is_empty() {
self.paragraph(&format!("{label}{text}"));
}
}
fn footnote(&mut self, block: &Block, marker: &str) {
let text = self.text.spans(&block.spans);
if text.is_empty() {
return;
}
if marker.is_empty() {
self.paragraph(&format!("\\begin{{quote}}\n\\small {text}\n\\end{{quote}}"));
} else {
self.paragraph(&format!(
"{{\\footnotesize\\noindent\\textsuperscript{{{}}}\\,{text}\\par}}",
escape(marker)
));
}
}
fn contents_entry(&mut self, block: &Block, level: u8, page: &str) {
let text = self.text.spans(&block.spans);
if text.is_empty() {
return;
}
let indent = f32::from(level.saturating_sub(1)) * CONTENTS_INDENT_EM;
let page = if page.is_empty() {
String::new()
} else {
format!("\\dotfill {}", escape(page))
};
self.paragraph(&format!("\\noindent\\hspace*{{{indent}em}}{text}{page}\\par"));
}
fn verbatim(&mut self, lines: &[String]) {
let body: Vec<String> = lines
.iter()
.map(|line| {
line.replace('\t', TAB_SPACES)
.replace("\\end{verbatim}", "\\end {verbatim}")
})
.collect();
let body = body.join("\n");
let body = body.trim_end();
if body.trim().is_empty() {
return;
}
self.paragraph(&format!(
"\\begin{{small}}\n\\begin{{verbatim}}\n{body}\n\\end{{verbatim}}\n\\end{{small}}"
));
}
fn equation(&mut self, block: &Block, image: Option<&ImageSpec>, number: Option<&str>) {
let body = match (equation_math(block, image, self.opts.equations), image) {
(Some(math), _) => latex(math).replace(['\n', '\r'], " "),
(None, Some(image)) => format!("\\vcenter{{\\hbox{{{}}}}}", self.picture(image, "eq")),
(None, None) => format!("\\text{{{}}}", self.text.spans(&block.spans)),
};
let tag = number
.map(|number| number.trim().trim_start_matches('(').trim_end_matches(')').trim())
.filter(|tag| !tag.is_empty());
let display = match tag {
Some(tag) => format!(
"\\begin{{equation*}}\n{body}\n\\tag{{{}}}\n\\end{{equation*}}",
escape(tag)
),
None => format!("\\[\n{body}\n\\]"),
};
if self.after_text && self.out.ends_with("\n\n") {
self.out.pop();
}
let label = self.anchor_label(block);
if label.is_empty() {
self.paragraph(&display);
} else {
self.paragraph(&format!("{label}\n{display}"));
}
}
fn figure(&mut self, block: &Block, kind: FloatKind, image: Option<&ImageSpec>) {
let caption = (!block.spans.is_empty()).then(|| self.caption(&block.spans));
if kind == FloatKind::Algorithm
&& block.table.is_none()
&& let Some(lines) = code::float_listing_lines(block)
{
if let Some(caption) = &caption {
self.paragraph(caption);
}
return self.verbatim(&lines);
}
let caption_first = caption_first(block, image);
let content = if let Some(table) = block.table.as_ref().filter(|table| !table.rows.is_empty()) {
*self.text.table_notes.borrow_mut() = Some(Vec::new());
let tabular = self.tabular(table);
let notes = self.text.table_notes.borrow_mut().take().unwrap_or_default();
Some(format!(
"\\begin{{center}}\n\\begin{{kakemonotable}}\n{tabular}\n\\end{{kakemonotable}}\n\\end{{center}}{}",
footnote_texts(¬es)
))
} else {
image.map(|spec| {
format!(
"\\begin{{center}}\n{}\n\\end{{center}}",
self.picture(spec, float_class(kind))
)
})
};
let mut parts: Vec<String> = Vec::new();
if caption_first && let Some(caption) = &caption {
parts.push(caption.clone());
}
parts.extend(content);
if !caption_first && let Some(caption) = caption {
parts.push(caption);
}
if parts.is_empty() {
return;
}
if block.table.is_none() && image.is_some() {
self.paragraph(&format!(
"\\noindent\\begin{{minipage}}{{\\linewidth}}\n{}\n\\end{{minipage}}\n\\medskip",
parts.join("\n\n")
));
} else {
for part in parts {
self.paragraph(&part);
}
}
}
fn caption(&self, spans: &[Span]) -> String {
let text = if let Some(first) = spans.first()
&& let Some(found) = CAP_LABEL.find(&first.text)
{
let label = first.text[..found.end()].trim_end();
let mut rest = spans.to_vec();
rest[0].text = first.text[label.len()..].to_string();
format!("\\textbf{{{}}} {}", escape(label), self.text.spans(&rest))
.trim_end()
.to_string()
} else {
self.text.spans(spans)
};
format!("{{\\small {text}\\par}}")
}
fn picture(&mut self, spec: &ImageSpec, hint: &str) -> String {
let width = spec.rect.width().max(1.0);
let src = self.images.region(spec, hint);
format!("\\kakemonopicture{{{width:.1}bp}}{{{src}}}")
}
fn tabular(&self, table: &Table) -> String {
let n_cols = table.n_cols.max(1);
let align: Vec<char> = (0..n_cols).map(|col| align_letter(table, col)).collect();
let spec: String = align.iter().collect();
let n_rows = table.rows.len();
let mut covered: Vec<Vec<Option<usize>>> = vec![vec![None; n_cols]; n_rows];
let mut lines = vec![format!("\\begin{{tabular}}{{{spec}}}"), "\\toprule".to_string()];
for (row_idx, row) in table.rows.iter().enumerate() {
let mut cells: Vec<String> = Vec::new();
let mut col = 0;
let mut row_cells = row.iter().filter(|cell| cell.col < n_cols).peekable();
while col < n_cols {
while row_cells.next_if(|cell| cell.col < col).is_some() {}
if let Some(width) = covered[row_idx][col] {
cells.push(multicolumn(width, align[col], String::new()));
col += width;
} else if let Some(cell) = row_cells.next_if(|cell| cell.col == col) {
let colspan = cell.colspan.clamp(1, n_cols - col);
let rowspan = cell.rowspan.clamp(1, n_rows - row_idx);
for below in covered.iter_mut().take(row_idx + rowspan).skip(row_idx + 1) {
below[col] = Some(colspan);
}
cells.push(self.cell(cell, colspan, rowspan, align[col]));
col += colspan;
} else {
cells.push(String::new());
col += 1;
}
}
lines.push(format!("{} \\\\", cells.join(" & ")));
if row_idx + 1 == table.header_rows && row_idx + 1 < n_rows {
lines.push("\\midrule".to_string());
}
}
lines.push("\\bottomrule".to_string());
lines.push("\\end{tabular}".to_string());
lines.join("\n")
}
fn cell(&self, cell: &TableCell, colspan: usize, rowspan: usize, align: char) -> String {
let text = self.text.spans(&cell.spans);
let text = if rowspan > 1 {
format!("\\multirow{{{rowspan}}}{{*}}{{{text}}}")
} else {
text
};
multicolumn(colspan, align, protect_start(&text))
}
}
fn mono_ratio(spans: &[Span]) -> f32 {
let count = |mono_only: bool| {
spans
.iter()
.filter(|span| !mono_only || span.style & MONO != 0)
.map(|span| span.text.chars().filter(|ch| !ch.is_whitespace()).count())
.sum::<usize>()
};
let total = count(false);
if total == 0 {
return 0.0;
}
count(true) as f32 / total as f32
}
fn author_rows(block: &Block) -> &[Vec<Span>] {
if block.rows.is_empty() {
std::slice::from_ref(&block.spans)
} else {
&block.rows[..]
}
}
fn align_letter(table: &Table, col: usize) -> char {
match table.col_align.get(col).copied() {
Some("center") => 'c',
Some("right") => 'r',
_ => 'l',
}
}
fn multicolumn(width: usize, align: char, text: String) -> String {
if width > 1 {
format!("\\multicolumn{{{width}}}{{{align}}}{{{text}}}")
} else {
text
}
}
fn protect_start(text: &str) -> String {
if text.starts_with(['[', '*']) {
format!("{{}}{text}")
} else {
text.to_string()
}
}
fn footnote_texts(notes: &[String]) -> String {
if notes.is_empty() {
return String::new();
}
let texts: String = notes
.iter()
.map(|note| format!("\\stepcounter{{footnote}}\\footnotetext{{{note}}}"))
.collect();
format!("\n\\addtocounter{{footnote}}{{-{}}}{texts}", notes.len())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn picture_folder_is_safe_for_tex() {
assert_eq!(
tex_path("my images/1706.03762v7_assets/"),
"my_images/1706.03762v7_assets"
);
assert_eq!(tex_path("a%b#c"), "a_b_c");
}
#[test]
fn unknown_characters_are_outside_latin() {
let chars: Vec<char> = unknown_chars("Erdős", "é ž 中 ſ").into_iter().collect();
assert_eq!(chars, vec!['ſ', '中']);
}
#[test]
fn options_of_items_are_protected() {
assert_eq!(protect_start("[1] Smith"), "{}[1] Smith");
assert_eq!(protect_start("Smith [1]"), "Smith [1]");
}
#[test]
fn table_with_spanning_cells() {
let cell = |col: usize, text: &str, colspan: usize, rowspan: usize| TableCell {
col,
colspan,
rowspan,
spans: vec![Span::plain(text)],
};
let table = Table {
n_cols: 3,
header_rows: 2,
col_align: vec!["left", "center", "right"],
rows: vec![
vec![cell(0, "Model", 1, 2), cell(1, "Score", 2, 1)],
vec![cell(1, "A", 1, 1), cell(2, "B", 1, 1)],
vec![cell(0, "x & y", 1, 1), cell(2, "[3]", 1, 1)],
],
rule_above: Vec::new(),
rule_bottom: Vec::new(),
rule_left: Vec::new(),
rule_right: Vec::new(),
geom: crate::model::TableGeom::default(),
};
let anchors = std::collections::HashSet::new();
let mut images = ImageStore {
opts: &HtmlOptions::default(),
jobs: Vec::new(),
vector: false,
};
let opts = LatexOptions::default();
let writer = Writer {
opts: &opts,
text: Text {
anchors: &anchors,
math: true,
table_notes: RefCell::default(),
},
images: &mut images,
out: String::new(),
group: Group::None,
item_open: false,
nested: 0,
after_text: false,
};
assert_eq!(
writer.tabular(&table),
"\\begin{tabular}{lcr}\n\\toprule\n\\multirow{2}{*}{Model} & \\multicolumn{2}{c}{Score} \\\\\n \
& A & B \\\\\n\\midrule\nx \\& y & & {}[3] \\\\\n\\bottomrule\n\\end{tabular}"
);
}
}