Pandoc: multiple footnotes next to one another? - latex

If I want to have two footnotes cited next to one another, separated by a comma, what is the syntax for doing so? The Pandoc documentation doesn't seem to specify how.
As an example of what I'm trying to accomplish:
Some text here [^fn1, ^fn2] ## this clearly isn't the syntax, I've tried this.
becomes:
Some text here 1, 2.

The syntax for multiple footnotes would be:
Some text here [^fn1][^fn2]
[^fn1]: foo
[^fn2]: bar
However, to separate them by comma in PDF output, you'll have to tell LaTeX to do so by including the following in your pandoc template:
\usepackage[multiple]{footmisc}
For HTML output, you'd have to to something similar in CSS:
<style>
.footnote-ref ~ .footnote-ref :before {
content: ', '
}
</style>

Related

Latex: \newcommand interpret # symbol problem

I defined a new command
\newcommand{\test}[1]{\href{https://github.com/microsoft/vscode/blob/main/package.json#1}{#1}}
When I use it as follows:
\test{#L4}
the url will be interpreted as:
https://github.com/microsoft/vscode/blob/main/package.json##L4
There is an extra # in the url, which is unexpected. What I really want is:
https://github.com/microsoft/vscode/blob/main/package.json#L4
which means line 4 of the package.json code
The easiest but no so elegant way to solve the problem is as follows.
\test{\#L4}
but what if other special characters like _ appear in the part of url I copy? It's boring to correct these meaningless grammar mistakes.
Is there any more elegant way to solve the problem? What I want is to copy plain text, which is part of url to the latex code and no extra efforts like adding \ escape character before # and other special characters are needed.
What I want is to copy plain text, which is part of url to the latex code and no extra efforts like adding \ escape character before # and other special characters are needed.
I am afraid it will require extra effort because # is used as a parameter for macros in LaTeX. You can play with redefining categories and when # is consumed, restore its original meaning.
I have another solution based on expl3 where I save the main address and create links with additional parts. See a small demo below
\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage[margin=1in]{geometry} % To fit long links without breaks
\ExplSyntaxOn
\str_new:N \l__xaddr_main_str
\str_new:N \l__xaddr_show_str
\cs_new:Npn \combine_addr:n #1 {
\str_set:Nn \l_tmpa_str {#1}
\str_concat:NNN \l__xaddr_show_str \l__xaddr_main_str \l_tmpa_str
}
\NewDocumentCommand\xsetmainaddr{v}{
\str_set:Nn \l__xaddr_main_str {#1}}
\NewDocumentCommand\xdisplay{v}{%
\str_if_empty:NF \l__xaddr_main_str {
\combine_addr:n {#1}
\str_use:N \l__xaddr_show_str
}}
\NewDocumentCommand\xhref{vv}{%
\str_if_empty:NF \l__xaddr_main_str {
\combine_addr:n {#1}
\href{\l__xaddr_show_str}{#2}
}}
\ExplSyntaxOff
\setlength\parindent{0pt} % To fit long links without breaks
\begin{document}
\xhref{#L4}{GitHub} % Nothing to display. The main address is not defined.
\xsetmainaddr{https://github.com/microsoft/vscode/blob/main/package.json}
\par\xdisplay{#L4} % Display the full address including #L4
\par\xdisplay{#something_else%20here} % all characters accepted
\par\xhref{#L4}{GitHub} % Generates link: <address>#L4
\bigskip
\xsetmainaddr{http://www.google.com} % New address
\par\xhref{}{Google} % Generates link
\end{document}

How to modify an inline element in Pandoc using lua filter?

I am beginner in Pandoc and Lua who is experimenting with converting Word documents to Markdown. I want to convert chapter headings in Word to paragraph of text in Markdown. Furthermore, I want to insert some text before and after the chapter headings.
To achieve that, I used the following lua filter (sample.lua)
function Header(el)
if el.level == 1 then
return {"something before (",el.content,") something after"}
end
end
after which I performed the conversion using
pandoc --lua-filter=sample.lua -s file.docx -t markdown -o file.txt
where file.docx is just minimal example document containing one chapter heading. However, using this filter, I obtained
something before (
Chapter title
) something after
What I want to get, however, is
something before (Chapter title) something after
but since (if I am not mistaken) el.content is inline element, there are linebreaks around it. I tried to solve this problem by using pandoc documentation and various lua functions, but to no avail, which is why I would kindly ask for help.
Try this instead:
function Header(el)
if el.level == 1 then
return {{"something before ("} .. el.content .. {") something after"}}
end
end
The reason is that el.content is a list of inline elements, and it can be be extended by concatenating lists with additional content. The operator .. is the concatenation operator; it works with strings and pandoc lists.

In Pandoc, how do I add a newline between authors through the YAML metablock without modifying the template?

I am trying to add a a couple of authors to a report I am writing. Preferably, the second author would appear on a new line after the first. I know I can modify the template to add a new field or the multiple author example given in the Pandoc readme. However, I wonder if there is any character I can use to insert a new line between authors directly in the metablock. So far I have tried \newline, \\, | with newline and space, <br>, <div></div>, and making the author list a string with newline or double spaces between author names, but nothing has worked. My desired output is pdf.
The problem isn't in the YAML metadata formatting (for which there are numerous ways to have multiline strings), but that the LaTeX \author command strips the newlines. But for PDF output (with LaTeX) you can do:
---
title: mytitle
author: '\protect\parbox{\textwidth}{\protect\centering Author: 1\\ Author: 2\\ Author 3}'
---
body text
You can go with a simple list to achieve this.
---
title: 'Any title comes here'
author:
- Author One
- Author Two
---
Another way is to rely on the title block that has a slightly different syntax.
% Any title comes here
% author(s) (separated by semicolons)
% date
Find additional variants in the metadata-block section of the pandoc manual.

How to escape whitepace in Rails?

I know that rails automatically escapes characters like '<' or '&', but this does nothing for multiple spaces next to each other. I would like to escape everything, including spaces.
I understand that normally you don't want to use and that you should use css instead. However, I'm trying to take user input and display it, so css isn't feasible.
For example, I have the user input: test . When I display it with <%=#user_input%> in the view, the extra whitespace is displayed as a single space (though it appears correctly in the source).
Is there an easy way to escape the whitespace? Should I just use h #user_input and then replace all the spaces?
The whitespace isn't removed. Browsers simply interpret multiple whitespace characters as a single space.
You could convert each space to if you want:
<%= raw #user_input.gsub(/\s/, " ") %>
You could alternatively replace each space with an empty <span class="whitespace"></span> tag, and then use CSS to style the whitespace 'characters' however you like.
Finally, you can do this with only CSS too using the white-space: pre style (example below).
http://jsfiddle.net/G3VnY/
Edit (to answer the follow-up in your comment)
<%= raw h("this is a sample & with ampersand.").gsub(/\s/, " ") %>
This escapes the & as & in the source (and will do similar for other HTML entities), and then does the " " to conversion.

LaTeX beamer: Code listings in notes

He,
How can I add a code listing to a beamer note slide?
I tried the following which doesn't work:
\note{{\tiny{This is a note
\begin{lstlisting}
foo bar
\end{lstlisting}}}
Any suggestions?
Verbatim-like commands and environments, which includes lstlisting, cannot appear as arguments to other commands (without losing their magic verbatimness regarding \, $, etc.)

Resources