diff --git a/src/lib.rs b/src/lib.rs
index 5582c55..6e7eea3 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2090,6 +2090,43 @@ include-in-header = ["file-in-root"]
");
}
+ #[test]
+ #[ignore]
+ fn right_to_left_fonts_lualatex() {
+ let cfg = r#"
+[book]
+language = "fa"
+
+[output.pandoc.profile.pdf]
+output-file = "book.pdf"
+pdf-engine = "lualatex"
+ "#;
+ let output = MDBook::init()
+ .mdbook_config(cfg.parse().unwrap())
+ .chapter(Chapter::new("", "C++", "chapter.md"))
+ .build();
+ insta::assert_snapshot!(output, @r#"
+ ├─ log output
+ │ INFO mdbook::book: Running the pandoc backend
+ │ INFO mdbook_pandoc::pandoc::renderer: Running pandoc
+ │ [WARNING] Missing character: There is no ف (U+0641) (U+0641) in font [lmroman12-bold]:+tlig;!
+ │ [WARNING] Missing character: There is no ه (U+0647) (U+0647) in font [lmroman12-bold]:+tlig;!
+ │ [WARNING] Missing character: There is no ر (U+0631) (U+0631) in font [lmroman12-bold]:+tlig;!
+ │ [WARNING] Missing character: There is no س (U+0633) (U+0633) in font [lmroman12-bold]:+tlig;!
+ │ [WARNING] Missing character: There is no ت (U+062A) (U+062A) in font [lmroman12-bold]:+tlig;!
+ │ [WARNING] Missing character: There is no م (U+0645) (U+0645) in font [lmroman12-bold]:+tlig;!
+ │ [WARNING] Missing character: There is no ط (U+0637) (U+0637) in font [lmroman12-bold]:+tlig;!
+ │ [WARNING] Missing character: There is no ا (U+0627) (U+0627) in font [lmroman12-bold]:+tlig;!
+ │ [WARNING] Missing character: There is no ل (U+0644) (U+0644) in font [lmroman12-bold]:+tlig;!
+ │ [WARNING] Missing character: There is no ب (U+0628) (U+0628) in font [lmroman12-bold]:+tlig;!
+ │ INFO mdbook_pandoc::pandoc::renderer: Wrote output to book/pdf/book.pdf
+ ├─ pdf/book.pdf
+ │
+ ├─ pdf/src/chapter.md
+ │ [Para [Span ("", [], [("dir", "ltr")]) [Str "C++"]]]
+ "#);
+ }
+
static BOOKS: Lazy = Lazy::new(|| Path::new(env!("CARGO_MANIFEST_DIR")).join("books"));
#[test]
diff --git a/src/pandoc/renderer.rs b/src/pandoc/renderer.rs
index e953fd4..3db1934 100644
--- a/src/pandoc/renderer.rs
+++ b/src/pandoc/renderer.rs
@@ -8,6 +8,7 @@ use std::{
};
use anyhow::Context as _;
+use mdbook::config::TextDirection;
use normpath::PathExt;
use tempfile::NamedTempFile;
@@ -170,6 +171,20 @@ impl Renderer {
additional_variables.push(("include-before", include_before))
}
+ if ctx.mdbook_cfg.book.realized_text_direction() == TextDirection::RightToLeft {
+ // Without this, LuaTeX errors on left-to-right text because the \LR command isn't defined, e.g.:
+ // Error producing PDF.
+ // ! Undefined control sequence.
+ // l.279 ...اوقات زبان Rust را با C و \LR
+ // (see https://github.com/google/comprehensive-rust/pull/2531#issuecomment-2567445055)
+ // Using luabidi was suggested in
+ // https://github.com/jgm/pandoc/issues/8460#issuecomment-1344881107
+ additional_variables.push((
+ "header-includes",
+ r"\ifLuaTeX\usepackage{luabidi}\fi".into(),
+ ));
+ }
+
let include_packages = packages
.needed()
.map(|package| format!(r"\usepackage{{{}}}", package.name()))