0

I have documents in markdown that are converted to PDF using pandoc, which relies on a latex engine to generate the output file.

The documents contain long web addresses as well as directory and file locations in disk. These are often written as normal text, and other times within backticks. Note these do not use \url{} or similar since that would require changing the documents.

I'd like these addresses to automatically wrap. If this was done at forward slash (/), for example, I think it would be sufficient. Currently, this is the behavior:

  • Address in backticks never wraps;
  • Address outside backticks wraps at hyphen; and
  • Address outside backticks never wraps at forward slash.

Example Input

# Title

## Subtitle

This is a long address: /users/foo/home/somelonglocation/somelonglocation/break-it-break-it-break-it-break-it-break-it/index.html

http://www.thissitedoesnotexit.corn/abcabcabcabcabcabcabcabcabc/defdefdefdefdef/ghighighi/jkljkljkjkljkljkljkljkljkljkljkljkljkljkljkl/mno-pqr-stu/index.html

In code backticks: `http://www.thissitedoesnotexit.corn/abcabcabcabcabcabcabcabcabc/defdefdefdefdef/ghighighi/jkljkljkjkljkljkljkljkljkljkljkljkljkljkljkl/mno-pqr-stu/index.html`

The end.

Compilation command: $ pandoc-local -o output.pdf input.md

Current Output

enter image description here

1 Answer 1

1

Pandoc's manual explains the mechanism that it uses to add set up information for each format. For pdf output Pandoc uses LaTeX.

With the command:

Pandoc -D latex > default.latex

you will get a copy of the used template. Inside it you will find at line 199 the following:

\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available

Perhaps, your LaTeX installation lacks xurl package or needs fine tuning. Of course, don't forget to use the apropiate reference link syntax.

I personally use the following instructions, that gave me a satisfactory end of line break:

% Localizador de recursos uniformes (URL) -----------------------
\usepackage[obeyspaces,spaces,hyphens]{xurl}
\def\UrlBreaks{\do\/\do-}

If you will include other tipes of uri probably the following will be convenient too:

\usepackage{uri} % Required url and hyperreference.
% \xxx{}, xxx: arxiv, asin, doi, hdl, nbn, pubmed, oid, tinyuri, 
% tinypuri, xmpp, citeurl, mailto, uref{target}{mostrado}

From the manual: If you use custom templates, you may need to revise them as pandoc changes. We recommend tracking the changes in the default templates, and modifying your custom templates accordingly. An easy way to do this is to fork the pandoc-templates repository and merge in changes after each pandoc release.

PS: You might use other programs to produce pdf. The manual gives more information.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .