首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >有什么方法可以防止R Markdown将LaTeX环境放在新的段落中?

有什么方法可以防止R Markdown将LaTeX环境放在新的段落中?
EN

Stack Overflow用户
提问于 2017-12-27 01:07:11
回答 1查看 725关注 0票数 1

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

在环境之前运行\vspace{-\baselineskip}可以很好地进行补偿,但当然,最好只告诉markdown不要在一开始就插入换行符。这有可能吗?如果不是,那么在每次对齐(和/或对齐*、聚集、聚集*等)开始之前自动运行\vspace{-\baselineskip}的最简单方法是什么?环境?

MWE:

代码语言:javascript
运行
复制
---
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*}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-27 14:47:16

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

代码语言:javascript
运行
复制
---
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),所以使用它可能更好

代码语言:javascript
运行
复制
header-includes:
  - \usepackage{etoolbox}
  - \AtBeginEnvironment{gather}{\vspace{\dimexpr-\baselineskip-\abovedisplayskip}}
  - \AtBeginEnvironment{gather*}{\vspace{\dimexpr-\baselineskip-\abovedisplayskip}}

您必须对所有amsmath-related显示路线执行此操作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47981566

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档