最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Pandoc keeps escaping my LaTeX math delimiters `$$$` and breaking inlinestandalone math in Markdown file - Stack Overflow

programmeradmin2浏览0评论

I'm trying to convert a Markdown file containing Latin/Cyrillic text and LaTeX math into a PDF using Pandoc. I have inline math delimited by $ ... $ and block math delimited by $$ ... $$. However, Pandoc is turning all my $ characters into \$, which causes LaTeX to throw an error because it never properly enters math mode.

Here’s an example snippet of my Markdown:

#### 2.1.1 Tenzori: skalari, vektori, matrice i višeredni tenzori

**Tenzor** (eng. _tensor_) je generalizacija pojma niza brojeva i može se posmatrati kao višedimenzionalni niz. 

1. **Skalar** (rang 0): Obični realni ili kompleksni broj. Skalar se može predstaviti kao $ \alpha \in \mathbb{R} $ (ili $ \alpha \in \mathbb{C} $ u slučaju kompleksnih brojeva).
2. **Vektor** (rang 1): Niz brojeva koji tipično reprezentuje neku veličinu sa određenim brojem komponenti. Na primer, vektor dužine $n$ je $ \mathbf{x} \in \mathbb{R}^n $.
3. **Matrica** (rang 2): Dvodimenzionalni niz brojeva ...
4. **Višeredni tenzor** (rang $\geq 3$): ...

But when I run:

pandoc in.md -o out.pdf --pdf-engine=xelatex -V mainfont="DejaVu Serif"

it gives me an error like:

! LaTeX Error: \symbb allowed only in math mode.

l.72  ...predstaviti kao \$ \alpha \in \mathbb
                                  ...

Which means that $ was turned into \$, so I'm never entering math mode.

I want Pandoc to recognize $ ... $ and $$ ... $$ as math delimiters, not turn them into escaped dollar signs. I've tried various combinations like --from=markdown+raw_tex+tex_math_dollars or --standalone, but it still ends up escaping my math in some contexts.

Which command line flags or extensions should I use so Pandoc doesn’t escape the $? Do I need a special metadata block or a specific yaml front matter to keep $ intact? Is there a known bug with certain versions of Pandoc that incorrectly escape $? I tried looking around but couldn't find anything that aligns with my setup and problem

My environment:

pandoc 3.1.11.1
Features: +server +lua
Scripting engine: Lua 5.4

XeTeX 3.141592653-2.6-0.999996 (TeX Live 2024/nixos)
kpathsea version 6.4.0

(I have all of the tex packages installed from nixos unstable, so they should be the latest versions)

Command used (among others): pandoc in.md -o out.pdf --pdf-engine=xelatex -V mainfont="DejaVu Serif"

Any guidance or workarounds would be greatly appreciated.

发布评论

评论列表(0)

  1. 暂无评论
ok 不同模板 switch ($forum['model']) { /*case '0': include _include(APP_PATH . 'view/htm/read.htm'); break;*/ default: include _include(theme_load('read', $fid)); break; } } break; case '10': // 主题外链 / thread external link http_location(htmlspecialchars_decode(trim($thread['description']))); break; case '11': // 单页 / single page $attachlist = array(); $imagelist = array(); $thread['filelist'] = array(); $threadlist = NULL; $thread['files'] > 0 and list($attachlist, $imagelist, $thread['filelist']) = well_attach_find_by_tid($tid); $data = data_read_cache($tid); empty($data) and message(-1, lang('data_malformation')); $tidlist = $forum['threads'] ? page_find_by_fid($fid, $page, $pagesize) : NULL; if ($tidlist) { $tidarr = arrlist_values($tidlist, 'tid'); $threadlist = well_thread_find($tidarr, $pagesize); // 按之前tidlist排序 $threadlist = array2_sort_key($threadlist, $tidlist, 'tid'); } $allowpost = forum_access_user($fid, $gid, 'allowpost'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); $access = array('allowpost' => $allowpost, 'allowupdate' => $allowupdate, 'allowdelete' => $allowdelete); $header['title'] = $thread['subject']; $header['mobile_link'] = $thread['url']; $header['keywords'] = $thread['keyword'] ? $thread['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>