gpt4 book ai didi

Rmd/knitr How to use a PDF LaTeX template that works(RMD/CONTINR如何使用有效的PDF LaTeX模板)

转载 作者:bug小助手 更新时间:2023-10-25 18:50:53 25 4
gpt4 key购买 nike



The Problem


I am knitting Rmd files to PDFs. I need to customize the title page (add another subtitle somwhere, add several logos, ...). This seems to go beyond what the YAML header is supposed to provide.

我正在将RMD文件编织到PDF。我需要自定义标题页(添加另一个副标题somwhere,添加几个标志,.)。这似乎超出了YAML头应该提供的内容。


So, I thought it'd be a good idea to modify the default latex template to suit my needs. What I want is to add, e.g., subtitle2 to my YAML header and have the template pick it up and render it in the correct position.

Shouldn't be too difficult, just look up the default template and modify it. (Let's hope that the metadata will just be available there, and I don't have to touch more than this.)

因此,我认为修改默认的LaTeX模板以满足我的需求是个好主意。例如,我想要的是在我的YAML头中添加Subtile2,并让模板拾取它并将其呈现在正确的位置。应该不会太难,只需查找默认模板并修改它。(让我们希望元数据只在那里可用,我不需要再多谈了。)


To my suprise, I didn't have pandoc installed. But the knitting in RStudio revealed that it uses a bundled pandoc (in /usr/lib/rstudio/resources/app/bin/quarto/bin/tools/pandoc). Running this (with -v) reveals that it's version 3.1.something. I then went to GitHub and downloaded the default.latex for the corresponding tag., and tried to knit the same Rmd with the otherwise untouched default.latex:

令我惊讶的是,我没有安装潘多克。但RStudio的编织显示,它使用的是捆绑的PanDoc(/usr/lib/rstudio/resources/app/bin/quarto/bin/tools/pandoc).版本运行这个命令(使用-v)会发现它是版本3.1之类的。然后我去GitHub下载了对应标签的default.lacex,并试图用其他未被触及的default.lacex来编织相同的RMD:


output:
pdf_document:
template: ./my-template.latex

Sadly, this throws an error like Missing number, treated as zero plus some w and a l.91, which I assume is a line number, but it does neither correspond to the template nor the generated tex file (nor the Rmd).

遗憾的是,这抛出了一个像Missing Numbers这样的错误,它被视为零加一些w和一个l.91,我认为它是一个行号,但它既不对应于模板,也不对应于生成的TeX文件(也不对应于RMD)。


Questions



  • Is my approach sane? Or am I missing some easier way to have a customized title page from the YAML header (I know, I could drop it altogether and recreate it in the body).

  • What's the default template used when I knit via RStudio? I cannot find a default.latex anywhere on my drive and I don't see similar templates anywhere within the RStudio files.

  • How could I reasonably debug what the error is? The message is super useless.

  • Now if I wanted this to work in different environments, possibly with different pandoc versions, this would probably break. Is it just a stupid approach? Should I just drop the YAML header and do everything by myself? I'd be surprised if the authors hadn't thought of customization options - the custom template is mentioned in many places.


更多回答

Take a look at github.com/svmiller/stevetemplates for examples of custom templates.

有关定制模板的示例,请访问githorb.com/svmiler/stevetemplates。

@user2554330 looks helpful, I'll perhaps sit down and work through some of them to try to answer my own question

@user2554330看起来很有帮助,我可能会坐下来仔细阅读其中的一些内容,尝试回答我自己的问题

优秀答案推荐
更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com