【问题标题】:Any way to keep R Markdown from putting a LaTeX environment in a new paragraph?有什么方法可以防止 R Markdown 将 LaTeX 环境放入新段落中?
【发布时间】:2017-12-26 17:07:11
【问题描述】:

aligngather 这样的环境显然是为在一段 LaTeX 文本中使用而设计的,因为文档文本和数学环境开始之间的两个换行符会插入一个惊人的两段的垂直空白.但是,Markdown 总是在其上方文本下方两行开始任何 LaTeX 环境,即使您在 Markdown 代码/文本的同一行开始环境,即使您在它之前放置 2 个空格以添加单行中断。由于 Markdown 没有原生的多行数学显示,这造成了两难。

在环境补偿足够好之前运行\vspace{-\baselineskip},但当然最好告诉markdown不要首先插入换行符。那可能吗?如果没有,那么在每个 align(和/或 align*、gather、gather* 等)环境开始之前自动运行 \vspace{-\baselineskip} 的最简单方法是什么?

MWE:

---
output:
  pdf_document:
    keep_tex: 1
---

The following environment will get marked up with an extra two lines between it and 
this text, putting it on a new paragraph and creating a lot of whitespace above it, 
whether or not there's any line breaks in the markdown code:
\begin{gather*}
A \\ B
\end{gather*}

This can of course be hackily corrected by subtracting vertical space: 
\vspace{-\baselineskip} \begin{gather*}
A \\ B
\end{gather*}

【问题讨论】:

    标签: latex r-markdown multiline


    【解决方案1】:

    在这种情况下,您可以做的最好的事情是使用etoolbox package 在每个特定环境的开头自动插入\vspace{-\baselineskip}

    ---
    output:
      pdf_document:
        keep_tex: 1
    header-includes:
      - \usepackage{etoolbox}
      - \AtBeginEnvironment{gather}{\vspace{-\baselineskip}}
      - \AtBeginEnvironment{gather*}{\vspace{-\baselineskip}}
    ---
    
    The following environment will get marked up with an extra two lines between it and 
    this text, putting it on a new paragraph and creating a lot of whitespace above it, 
    whether or not there's any line breaks in the markdown code:
    \begin{gather*}
    A \\ B
    \end{gather*}
    
    This can of course be hackily corrected by subtracting vertical space: 
    \begin{gather*}
    A \\ B
    \end{gather*}
    

    然而,这并不是最优的,因为环境插入的间隙取决于前一段结尾的文本数量。由于 Pandoc 的处理,金额始终相同(\abovedisplayskip),因此使用起来可能“更好”

    header-includes:
      - \usepackage{etoolbox}
      - \AtBeginEnvironment{gather}{\vspace{\dimexpr-\baselineskip-\abovedisplayskip}}
      - \AtBeginEnvironment{gather*}{\vspace{\dimexpr-\baselineskip-\abovedisplayskip}}
    

    您必须为所有与amsmath 相关的显示对齐方式执行此操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-05
      • 2022-06-22
      • 2013-12-06
      • 2014-01-01
      • 1970-01-01
      • 2010-11-26
      相关资源
      最近更新 更多