Trying to create rich text link to source citation for inline citation with pandoc citeproc - pandoc

Trying to create an output that would allow the URL part of a citation to appear as clickable rich text link to source file.
So far I have tried to create a custom CSL file that would output as (TITLE, DATE) ([SOURCE LINK](URL)) so that when I run it through pandoc it would turn into a rich text link when converted to DOCX, HTML, PDF, etc.
However, when I run the following command it populates it as escaped markdown that would not result as a rich link but just the raw text.
pandoc input.md -o output.md --citeproc --csl chicago-custom.csl --bibliography references.bib
I also tried to output as html but it creates the link for the URL, but not the "SOURCE LINK" part and looks like this: /[SOURCE LINK]/(URL) for markdown or URL with html output
Is there a different approach than custom CSL to do this?

Related

Add logo to title page when backend is docbook

I am trying to customise the title page where the backend output is docbook. title, subtitle etc are all output correctly. But I cannot seem to get the title logo to output.
I have tried:
:title-logo-image: image:images/titleimage.png[]
The only way I can get this to kind-of work is to directly embed the image in the title text. But that is not ideal.
Is this possible when using docbook?
Since you convert AsciiDoc to DocBook I am assuming you are writing a book. The parameter title-logo-image you are using is not for asciidoctor (conversion to HTML and DocBook) but for asciidoctor-pdf (conversion to PDF), see https://docs.asciidoctor.org/pdf-converter/latest/title-page/#logo. If you are okay with PDF instead of DocBook you should try asciidoctor-pdf, it also allows you to customize your page it is pretty nice.
I am not sure what you expect though, is it a big picture on the first page? are you talking about the cover? If so you might want to create your own DocBook cover element and inject it in your DocBook file. This is possible in AsciiDoc by using a DocInfo file. You create a docinfo.dbk file where you write the <cover> element and the file content will then be injected in the <info> Element in the resulting DocBook file.

How to include images from the epub template with pandoc?

I've altered the epub template to display more information. It works fine, except when I specify images that refer to a local file. e.g. <img src = "my_file.png">. The code is there in the epub, but the image file isn't.
Pandoc does not parse the template as HTML, so it misses the <img> element when collecting media elements for inclusion in the EPUB. A quick and simple work-around is to list the missing images in some unused metadata field. E.g.,
---
missing-images: |
![](my_file.png)
---
Store the above in a file and pass it to pandoc via --metadata-file. This makes pandoc aware of the file, forcing its inclusion.
One could automate it by letting pandoc parse the template and extract the image information, e.g. with a pandoc Lua filter, but that's likely to be more trouble than it's worth.

How to avoid img size tags on markdown when converting docx to markdown?

I'm converting docx files using pandoc 1.16.0.2 and everything works great except right after each image, the size attributes are showing as text in teh
![](./media/media/image4.png){width="3.266949912510936in"
height="2.141852580927384in"}
So it shows the image fine in the md but also the size tag as plain text right behind/after/below each image. The command I'm using is:
pandoc --extract-media ./media2 -s word.docx markdown -o exm_word2.md
I've read the manual as best I can but don’t see any flags to use to control this. Also most searches are coming up where people want to have the attributes and control them.
Any suggestions to kill the size attributes or is my markdown app (MarkdownPad2 - v-2.5.x) reading this md wrong?
Use -w gfm as argument in the command line to omit the dimensional of Images.
You could write a filter to do this. You'll need to install panflute. Save this as remove_img_size.py:
import panflute as pf
def change_md_link(elem, doc):
if isinstance(elem, pf.Image):
elem.attributes.pop('width', None)
elem.attributes.pop('height', None)
return elem
if __name__ == "__main__":
pf.run_filter(change_md_link)
Then compile with
pandoc word.docx -F remove_img_size.py -o exm_word2.md
There are two ways to do this: either remove all image attributes with a Lua filter or choose an output format that doesn't support attributes on images.
Output format
The easiest (and most standard-compliant) method is to convert to commonmark. However, CommonMark allows raw HTML snippets, so pandoc tries to be helpful and creates an HTML <img> element for images with attributes. We can prevent that by disabling the raw_html format extension:
pandoc --to=commonmark-raw_html ...
If you intend to publish the document on GitHub, then GitHub Flavored Markdown (gfm) is a good choice.
pandoc --to=gfm-raw_html ...
For pandoc's Markdown, we have to also disable the link_attributes extension:
pandoc --to=markdown-raw_html-link_attributes ...
This last method is the only one that works with older (pre 2.0) pandoc version; all other suggestions here require newer versions.
Lua filter
The filter is straight-forward, it simply removes all attributes from all images
function Image (img)
img.attr = pandoc.Attr{}
return img
end
To apply the filter, we need to save the above into a file no-img-attr.lua and pass that file to pandoc with
pandoc --lua-filter=no-img-attr.lua ...

Retain YAML data when converting markdown to html with pandoc

Is it possible to retain the yaml header in a markdown file when converting to html using pandoc?
Or, even better, convert the yaml to json and keep it in the converted file.
E.g.,
---
title: My Title
subtitle: My Subtitle
...
# Pandoc
We Love pandoc
To:
---
title: My Title
subtitle: My Subtitle
...
<h1>Pandoc</h1>
<p>We Love pandoc</p>
Or something like:
{title: "My Title", subtitle: "My Subtitle"}
<h1>Pandoc</h1>
<p>We Love pandoc</p>
Update
So, I guess I'll use templates and do something like this:
{title: $title$, subtitle:$subtitle$}
Not out of the box as HTML doesn't have the concept of a YAML or JSON block (without javascript). You can customise your output with templates:
Templates
To see the default template that is used, just type
pandoc -D FORMAT
A custom template can be specified using the --template option. You
can also override the system default templates for a given output
format FORMAT by putting a file templates/default.FORMAT in the user
data directory (see --data-dir
So you can create a custom template that deals with values in the YAML metadata block as you see fit.
Examples 5.11 YAML metadata block
Template variables will be set automatically from the metadata. Thus,
for example, in writing HTML, the variable abstract will be set to the
HTML equivalent of the markdown in the abstract field:

How to remove `\centering` tag from a figure block in LaTeX generated from pandoc?

When generating a PDF from markdown using pandoc, the markdown is converted into LaTeX. I am using a customized template to style my PDF.
When I create an image link:
![Alt text](image.png)
the following LaTeX is generated.
\begin{figure}[htbp]
\centering
\includegraphics{image.png}
\caption{Alt text}
\end{figure}
The image is, not surprisingly, centered on the PDF.
How do I prevent the \centering tag from being generated?
Probably you can't, but if your document does not use \centering for any other purpose, you can redefine it at as "void" (\relax) before it is used. You can do this in several ways:
Include the line \def\centering{\relax} at the beginning of your pandoc document. Pandoc passes all latex code "as is" to the resulting .tex file.
Modify your latex template and include the definition of \centering at the appropiate point (for example, just before \begin{document}
If you are using pandoc's standard template, you can still insert code into it at compile-time, using pandoc's --variable option to define the variable header-includes. For example:
pandoc -s --variable:header-includes="\\def\\centering{\\relax}" yourdoc.markdown -o yourdoc.tex

Resources