Closed ChoCho66 closed 1 year ago
晚些我测试看看问题修复下,beamer 也是 PDF 类型,理论上应该 OK。
测试了下,主要原因是因为 beamer 会将每一个片子放在 \begin{frame} \end{frame}
环境中,但这里面不允许有浮动元素,所以利用 pdf-placement
参数指定内容放置的位置即可,例如 #| pdf-placement: "H"
。
但是不是所有的示例代码都在 beamer 下测试通过了,尤其是带有自定义命令的部分,例如,当使用 \renewcommand{\And}{\textbf{and}~}
时会报错,具体还没来得及看是问什么,先使用 algorithm 包自带的关键字吧,后续有时间会再排查修复下。
感谢回答! 我刚刚测试了自定义命令的部分。 在 beamer 上出问题感觉是转成 tex 时,他的环境是
\documentclass[
ignorenonframetext,
]{beamer}
有 ignorenonframetext
时就没法使用自定义的东西。
我在 overleaf 上将 ignorenonframetext
给 comment 后是可以执行的。
(他会侦测到 \renewcommand{\Not}{\textbf{not}~}
有问题,好像应该改成 \newcommand{\Not}{\textbf{not}~}
)。
只是我不知道怎么在 quarto 上设定让它不要使用 ignorenonframetext
。
以下是我使用的 qmd 和其转成的 tex 档 以及 将ignorenonframetext
comment 在 overleaf 上的截图。
参考 https://github.com/jgm/pandoc/issues/3295,将重新定义的命令放在每页上就可以正常使用了,但需要在所有用到的页面都放上。如果将其放在 include-in-header
中,也会有一些小问题,后面系统引入的一些包可能会把你定义的命令再次重定义(例如:\Not
)。
---
title: "Quarto Pseudocode Extension Example"
filters:
- pseudocode
format:
beamer:
include-in-header:
text: |
\usepackage{xeCJK}
pdf-engine: xelatex
keep-tex: true
---
## Test atoms
Test atoms is shown as @alg-test-atoms.
\renewcommand{\Return}{\State \textbf{return}~}
\newcommand{\Print}{\State \textbf{print}~}
\newcommand{\Break}{\State \textbf{break}}
\newcommand{\Continue}{\State \textbf{continue}}
\newcommand{\True}{\textbf{true}}
\newcommand{\False}{\textbf{false}}
\renewcommand{\And}{\textbf{and}~}
\newcommand{\Or}{\textbf{or}~}
\renewcommand{\Not}{\textbf{not}~}
\newcommand{\To}{\textbf{to}~}
\newcommand{\DownTo}{\textbf{downto}~}
```pseudocode
#| label: alg-test-atoms
#| html-line-number: false
#| html-no-end: true
#| pdf-line-number: false
#| pdf-placement: "H"
\begin{algorithm}
\caption{Test atoms}
\begin{algorithmic}
\State \textbf{Specials:} \{ \} \$ \& \# \% \_
\State \textbf{Bools:} \And \Or \Not \True \ \False
\State \textbf{Carriage return:} first line \\ second line
\State \textbf{Text-symbols:} \textbackslash
\State \textbf{Quote-symbols:} `single quotes', ``double quotes''
\State \textbf{Math:} $(\mathcal{C}_m)$, $i \gets i + 1$, $E=mc^2$, \( x^n + y^n = z^n \), $\$$, \(\$\)
\end{algorithmic}
\end{algorithm}
在 html 以及 pdf 格式上,皆可以成功。 但在 beamer 上会失败。 下面是测试的失败资讯以及测试的小范本。
失败的资讯
``` Rendering PDF running xelatex - 1 This is XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023) (preloaded format=xelatex) restricted \write18 enabled. entering extended mode updating tlmgr updating existing packages ERROR: compilation failed- error LaTeX Error: Not in outer par mode. See the LaTeX manual or LaTeX Companion for explanation. Type H测试的小范本
```` --- title: "Quarto Pseudocode Extension Example" filters: - pseudocode format: beamer: include-in-header: text: | \usepackage{xeCJK} include-before-body: text: | \renewcommand{\Return}{\State \textbf{return}~} \newcommand{\Print}{\State \textbf{print}~} \newcommand{\Break}{\State \textbf{break}} \newcommand{\Continue}{\State \textbf{continue}} \newcommand{\True}{\textbf{true}} \newcommand{\False}{\textbf{false}} \renewcommand{\And}{\textbf{and}~} \newcommand{\Or}{\textbf{or}~} \renewcommand{\Not}{\textbf{not}~} \newcommand{\To}{\textbf{to}~} \newcommand{\DownTo}{\textbf{downto}~} pdf-engine: xelatex keep-tex: true --- ## Test text-style Test text-style is shown as @alg-test-text-style. ```pseudocode #| label: alg-test-text-style #| html-indent-size: "1.2em" #| html-comment-delimiter: "//" #| html-line-number: true #| html-line-number-punc: ":" #| html-no-end: false #| pdf-placement: "htb!" #| pdf-line-number: true \begin{algorithm} \caption{Test text-style} \begin{algorithmic} \State asd \end{algorithmic} \end{algorithm} ``` ````请问需要做什么调整才能在 beamer 格式上运作呢?