【问题标题】:RMarkdown and YAML not able to load packagesRMarkdown 和 YAML 无法加载包
【发布时间】:2017-03-09 02:32:30
【问题描述】:

出于各种原因,我想将一段文本从 Latex 转换为 Markdown。但我无法让它发挥作用。如果我加载所有包并且只输入“yo”作为文本,它会返回一个错误。

Error in yaml::yaml.load(enc2utf8(string), ...) : 
  Scanner error: while scanning a directive at line 5, column 1could not find expected directive name at line 5, column 2
Calls: <Anonymous> ... yaml_load_utf8 -> mark_utf8 -> <Anonymous> -> .Call
Execution halted

很多人之前都遇到过这个错误,但到目前为止我还没有看到有人遇到过这个错误,也没有遇到过这样的包的解决方案。

  1. 我们可以在序言中写 cmets "%" 吗?
  2. 如何在 RMarkdown 中添加我的乳胶包?
  3. 如果我用word导出它会起作用吗?

这是我的代码:

---
title: "rest"
author: "Me"
date: '2016-10-26'
header-includes:
% Titles
   - \usepackage{titlesec} 
% figure
   - \usepackage{color}
   - \usepackage{graphicx} % Enhanced support for graphics
   - \usepackage{subfig} % subfigure environment
   - \usepackage{float} % Improved interface for floating objects
   - \usepackage{rotating} % Rotation tools, including rotated full-page floats
  % \usepackage[labelfont=bf]{caption} % Customising captions in floating environments
% tables
   - \usepackage[table]{xcolor} % Driver-independent color extensions 
   - \usepackage{array} %  Extending the array and tabular environments
   - \usepackage{longtable} %  Allow tables to flow over page boundaries
   - \usepackage{multirow} % Create tabular cells spanning multiple rows
% math
   - \usepackage{amssymb} % some weird math symbols
   - \usepackage{amsthm}
   - \usepackage{amsmath} % AMS mathematical facilities for LATEX
% documents aspect
   - \usepackage{lineno} %  Line numbers on paragraphs
   - \usepackage[top=2.2cm, left=2.2cm,right=2.2cm,bottom=4.2cm]{geometry} % Flexible and complete interface to document d=imensions
  % see geometry.pdf on how to lay out the page. There's lots.
   - \usepackage[utf8]{inputenc} % Accept different input encodings
   - \usepackage[T1]{fontenc}
   - \usepackage{lscape} % Place selected parts of a document in landscape
   - \usepackage{babel}
% reference in text
   - \usepackage[unicode=true, pdfusetitle, bookmarks=true, bookmarksnumbered=false, bookmarksopen=false, breaklinks=true, pdfborder={0 0 0}, backref=page,colorlinks=true]
 {hyperref}
   - \newcommand*{\fullref}[1]{\hyperref[{#1}]{\autoref*{#1} \nameref*{#1}}}
% bibliography
  %\usepackage[style=authoryear, backend=bibtex,bibencoding=ascii]{biblatex} % Bibliographies in LATEX using BibTEX for sorting only
   - \usepackage{natbib} % Flexible bibliography support
  % \usepackage{translation-natbib-fr} %French translation of the documentation of natbib
  %\renewbibmacro{in:}{}
  %\bibliography{yo.bib}
  % \ref{} makes reference to a \label{} set in a table or figure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
   - \theoremstyle{plain}
title: "data"
author: "Me"
date: '2016-10-26'
output:
  pdf_document: default
  word_document: default
documentclass: article % - \documentclass[english]{scrartcl
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
YO

【问题讨论】:

    标签: r yaml markdown rstudio r-markdown


    【解决方案1】:

    您的标头包含无效的 YAML,内联 cmets 需要 #:

    ---
    title: "rest"
    author: "Me"
    date: '2016-10-26'
    header-includes:
    # Titles
       - \usepackage{titlesec} 
    # figure
       - \usepackage{color}
       - \usepackage{graphicx}
    ...
    

    您还需要对 YAML 映射键进行重复数据删除。当然,您可以将 RMarkdown 渲染到 Word,但需要注意的是 LaTeX 特定格式不会自动延续。

    【讨论】:

    • 我现在唯一的问题是在我的新命令- \newcommand*{\fullref}[1]{\hyperref[{#1}]{\autoref*{#1} \nameref*{#1}}} 中我有英镑# 符号。这使它们成为 cmets,但我不想这样做。有没有办法以不同的方式对待他们?同时,我从我加载的包中收到许多其他错误消息:! Undefined control sequence. l.86 \theoremstyle! Argument of \paragraph has an extra }. &lt;inserted text&gt; \par l.1276 \ttl@extract\paragraph! LaTeX Error: Option clash for package geometry. 等。但是当我在 LaTeX 中运行它们时,它很好......
    猜你喜欢
    • 2017-02-22
    • 1970-01-01
    • 2014-09-18
    • 2021-08-20
    • 2020-10-12
    • 2021-10-06
    • 2018-03-11
    • 2019-10-16
    • 2017-09-24
    相关资源
    最近更新 更多