更新

更新

更新

我根据以下评论的建议重写了该帖子,并提供了 MWE。

问题

在生成论文末尾的参考文献列表时,PDF 输出有两个我无法解决的问题。

1) 链接溢出页面边框但应在破折号处分页。

2) 书目项目分为多页,但应保持为一个块。

问题

我的文档

我正在使用 RMarkdown 和 Pandoc 生成基于以下内容的 PDFhttp://rmarkdown.rstudio.com/authoring_pandoc_markdown.html#citations

根据文档,参考文献列表位于文档末尾。因此,我没有任何类似的东西\printbibliography

在 RStudio 中使用“knit pdf”似乎执行:

/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc +RTS -K512m -RTS MWE.utf8.md 
--to latex 
--from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash 
--output MWE.tex 
--template /usr/local/lib/R/3.3/site-library/rmarkdown/rmd/latex/default-1.15.2.tex 
--highlight-style tango 
--latex-engine /Library/TeX/texbin/xelatex 
--variable graphics=yes 
--bibliography library.bib 
--filter /Applications/RStudio.app/Contents/MacOS/pandoc/pandoc-citeproc

梅威酉

---
output: 
  pdf_document:
    latex_engine: xelatex
    keep_tex: true
bibliography: library.bib
fontsize: 12pt
geometry:
  margin = 1.2in,
  paper = a4paper,
  inner = 1.5cm,
  bindingoffset = 2cm,
  outer = 2cm,
  top = 2.5cm,
  bottom = 2.5cm
header-includes:
- \usepackage{setspace}
- \usepackage{lipsum}
- \onehalfspacing
---

#  Content

@Boner2015 states that...

I need another line...

And another...

\lipsum[1-3]

# References

\setlength{\parindent}{-0.2in}
\setlength{\leftskip}{0.2in}
\setlength{\parskip}{8pt}
\noindent

图书馆参考书目

@misc{Boner2015,
author = {Bon{\'{e}}r, Jonas},
title = {{Interview with Tony Rae Moore: Typesafe AMA Podcast Ep. 03 feat. How Akka Actors Help Build Microservices with Jonas Bon{\'{e}}r}},
url = {https://www.lightbend.com/blog/typesafe-ama-podcast-ep-03-feat-akka-actors-microservices-jonas-boner},
urldate = {2016-11-22},
year = {2015}
}

生成的 MWE.tex

\documentclass[12pt,]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
\else % if luatex or xelatex
  \ifxetex
    \usepackage{mathspec}
  \else
    \usepackage{fontspec}
  \fi
  \defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
  \newcommand{\euro}{â¬}
\fi
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\IfFileExists{microtype.sty}{%
\usepackage{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\usepackage[margin = 1.2in, paper = a4paper, inner = 1.5cm, bindingoffset = 2cm,
outer = 2cm, top = 2.5cm, bottom = 2.5cm]{geometry}
\usepackage{hyperref}
\PassOptionsToPackage{usenames,dvipsnames}{color} % color is loaded by hyperref
\hypersetup{unicode=true,
            pdfborder={0 0 0},
            breaklinks=true}
\urlstyle{same}  % don't use monospace font for urls
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\setlength{\emergencystretch}{3em}  % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{0}

%%% Use protect on footnotes to avoid problems with footnotes in titles
\let\rmarkdownfootnote\footnote%
\def\footnote{\protect\rmarkdownfootnote}

%%% Change title format to be more compact
\usepackage{titling}

% Create subtitle command for use in maketitle
\newcommand{\subtitle}[1]{
  \posttitle{
    \begin{center}\large#1\end{center}
    }
}

\setlength{\droptitle}{-2em}
  \title{}
  \pretitle{\vspace{\droptitle}}
  \posttitle{}
  \author{}
  \preauthor{}\postauthor{}
  \date{}
  \predate{}\postdate{}


\usepackage{setspace}
\usepackage{lipsum}
\onehalfspacing

% Redefines (sub)paragraphs to behave more like sections
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi

\begin{document}

\section{Content}\label{content}

Bonér (2015) states that\ldots{}

I need another line\ldots{}

And another\ldots{}

\lipsum[1-3]

\section{References}\label{references}

\setlength{\parindent}{-0.2in} \setlength{\leftskip}{0.2in}
\setlength{\parskip}{8pt} \noindent

\hypertarget{refs}{}
\hypertarget{ref-Boner2015}{}
Bonér, Jonas. 2015. ``Interview with Tony Rae Moore: Typesafe AMA
Podcast Ep. 03 Feat. How Akka Actors Help Build Microservices with Jonas
Bonér.''
\url{https://www.lightbend.com/blog/typesafe-ama-podcast-ep-03-feat-akka-actors-microservices-jonas-boner}.

\end{document}

答案1

对于问题 1,我在header-includes:

\def\UrlBreaks{\do\/\do-\do?}

它添加了可导致 url 中断的额外字符,这显然可以在 hyperref 已加载时完成。

问题 2 的解决方案对我来说不起作用。

答案2

感谢@jon 和@moewe,问题 1\PassOptionsToPackage{hyphens}{url}可以通过在加载之前放置来解决hyperref( )。 在我的情况下,这在RMarkdown YAML 中\usepackage{hyperref}是不可能的,因为它使用了一些已经加载的默认 .tex 文件。 对我来说,修改默认 .text 文件是可以的。header-include:hyperref

关于问题 2显然,使用 Pandoc 和 CSL 的 RMarkdown 会为每个参考书目项目生成以下格式的段落(以空行分隔)

\hypertarget{ref-Boner2015}{}
Bonér, J. (2015). \emph{Interview with Tony Rae Moore: Typesafe AMA
Podcast Ep. 03 feat. How Akka Actors Help Build Microservices with Jonas
Bonér}. {[}Online{]}. Available from:
\url{https://www.lightbend.com/blog/typesafe-ama-podcast-ep-03-feat-akka-actors-microservices-jonas-boner}.
{[}Accessed: 22 November 2016{]}.

通常情况下,根据如何避免段落内分页?这会起作用:

\widowpenalties 1 10000
\raggedbottom

但是,阻止\hypertarget分页符(多个 \hypertarget 是否溢出页面?)。因此,另外,我必须\leavevmode在每个前面放置一个\hypertarget,从而导致覆盖\hypertarget

\usepackage{letltxmacro}
\LetLtxMacro{\oldhypertarget}{\hypertarget}
\renewcommand{\hypertarget}[2]{\leavevmode\oldhypertarget{#1}{#2}}

相关内容