summaryrefslogtreecommitdiff
path: root/paper/lua-filters/short-captions
diff options
context:
space:
mode:
Diffstat (limited to 'paper/lua-filters/short-captions')
-rw-r--r--paper/lua-filters/short-captions/Makefile18
-rw-r--r--paper/lua-filters/short-captions/README.md52
-rw-r--r--paper/lua-filters/short-captions/expected-1.tex67
-rw-r--r--paper/lua-filters/short-captions/expected-2.tex67
-rw-r--r--paper/lua-filters/short-captions/fig.pdfbin0 -> 56971 bytes
-rw-r--r--paper/lua-filters/short-captions/short-captions.lua37
6 files changed, 241 insertions, 0 deletions
diff --git a/paper/lua-filters/short-captions/Makefile b/paper/lua-filters/short-captions/Makefile
new file mode 100644
index 0000000..756cf2b
--- /dev/null
+++ b/paper/lua-filters/short-captions/Makefile
@@ -0,0 +1,18 @@
+LF = --lua-filter=short-captions.lua
+F = -F pandoc-crossref
+
+test:
+ @pandoc $(LF) README.md -w latex | diff --strip-trailing-cr expected-1.tex -
+
+crossref:
+ @echo testing short-captions.lua after pandoc-crossref
+ @pandoc $(F) $(LF) README.md -w latex | diff --strip-trailing-cr expected-2.tex -
+ @echo testing short-captions.lua before pandoc-crossref
+ @pandoc $(LF) $(F) README.md -w latex | diff --strip-trailing-cr expected-2.tex -
+
+readme:
+ @pandoc -s $(F) $(LF) README.md -o README.pdf
+
+latex:
+ @pandoc -s $(F) $(LF) README.md -o README.tex
+
diff --git a/paper/lua-filters/short-captions/README.md b/paper/lua-filters/short-captions/README.md
new file mode 100644
index 0000000..2721004
--- /dev/null
+++ b/paper/lua-filters/short-captions/README.md
@@ -0,0 +1,52 @@
+---
+title: "short-captions.lua"
+lof: true
+---
+
+# Short captions in \LaTeX\ output
+
+For latex output, this filter uses the attribute `short-caption` for
+figures so that the attribute value appears in the List of Figures, if
+one is desired.
+
+# Usage
+
+Where you would have a figure in, say, markdown as
+
+ ![The caption](foo.png )
+
+You can now specify the figure as
+
+ ![The long caption](foo.png){short-caption="a short caption"}
+
+If the document metadata includes `lof:true`, then the List of Figures
+will use the short caption. This is particularly useful for students
+writing dissertations, who often have to include a List of Figures in
+the front matter, but where figure captions themselves can be quite
+lengthy.
+
+ pandoc --lua-filter=short-captions.lua article.md -o article.tex
+
+ pandoc --lua-filter=short-captions.lua article.md -o article.pdf
+
+
+
+# Example
+
+@Fig:shortcap is an interesting figure with a long caption, but a short
+caption in the List of Figures.
+
+![This is an *extremely* interesting figure that has a lot of detail I
+will need to describe in a few sentences. This figure has a short
+caption that will appear in the list of figures. Other attributes are
+preserved](fig.pdf){#fig:shortcap short-caption="A short caption with
+math $x^n + y^n = z^n$" width="50%"}
+
+
+# Limitations
+
+- The filter will process the `short-caption` attribute value as pandoc
+ markdown, regardless of the input format.
+- It does not work for tables and listings yet.
+- But it works with pandoc-crossref, regardless of the order of
+ application.
diff --git a/paper/lua-filters/short-captions/expected-1.tex b/paper/lua-filters/short-captions/expected-1.tex
new file mode 100644
index 0000000..a28bb7e
--- /dev/null
+++ b/paper/lua-filters/short-captions/expected-1.tex
@@ -0,0 +1,67 @@
+\hypertarget{short-captions-in-output}{%
+\section{\texorpdfstring{Short captions in
+\LaTeX~output}{Short captions in ~output}}\label{short-captions-in-output}}
+
+For latex output, this filter uses the attribute \texttt{short-caption}
+for figures so that the attribute value appears in the List of Figures,
+if one is desired.
+
+\hypertarget{usage}{%
+\section{Usage}\label{usage}}
+
+Where you would have a figure in, say, markdown as
+
+\begin{verbatim}
+![The caption](foo.png )
+\end{verbatim}
+
+You can now specify the figure as
+
+\begin{verbatim}
+![The long caption](foo.png){short-caption="a short caption"}
+\end{verbatim}
+
+If the document metadata includes \texttt{lof:true}, then the List of
+Figures will use the short caption. This is particularly useful for
+students writing dissertations, who often have to include a List of
+Figures in the front matter, but where figure captions themselves can be
+quite lengthy.
+
+\begin{verbatim}
+pandoc --lua-filter=short-captions.lua article.md -o article.tex
+
+pandoc --lua-filter=short-captions.lua article.md -o article.pdf
+\end{verbatim}
+
+\hypertarget{example}{%
+\section{Example}\label{example}}
+
+@Fig:shortcap is an interesting figure with a long caption, but a short
+caption in the List of Figures.
+
+\hypertarget{fig:shortcap}{%
+\begin{figure}
+\centering
+\includegraphics[width=0.5\textwidth,height=\textheight]{fig.pdf}
+\caption[{A short caption with math \(x^n + y^n = z^n\)}]{This is an
+\emph{extremely} interesting figure that has a lot of detail I will need
+to describe in a few sentences. This figure has a short caption that
+will appear in the list of figures. Other attributes are preserved}
+\label{fig:shortcap}
+\end{figure}
+}
+
+\hypertarget{limitations}{%
+\section{Limitations}\label{limitations}}
+
+\begin{itemize}
+\tightlist
+\item
+ The filter will process the \texttt{short-caption} attribute value as
+ pandoc markdown, regardless of the input format.
+\item
+ It does not work for tables and listings yet.
+\item
+ But it works with pandoc-crossref, regardless of the order of
+ application.
+\end{itemize}
diff --git a/paper/lua-filters/short-captions/expected-2.tex b/paper/lua-filters/short-captions/expected-2.tex
new file mode 100644
index 0000000..95444b3
--- /dev/null
+++ b/paper/lua-filters/short-captions/expected-2.tex
@@ -0,0 +1,67 @@
+\hypertarget{short-captions-in-output}{%
+\section{\texorpdfstring{Short captions in
+\LaTeX~output}{Short captions in ~output}}\label{short-captions-in-output}}
+
+For latex output, this filter uses the attribute \texttt{short-caption}
+for figures so that the attribute value appears in the List of Figures,
+if one is desired.
+
+\hypertarget{usage}{%
+\section{Usage}\label{usage}}
+
+Where you would have a figure in, say, markdown as
+
+\begin{verbatim}
+![The caption](foo.png )
+\end{verbatim}
+
+You can now specify the figure as
+
+\begin{verbatim}
+![The long caption](foo.png){short-caption="a short caption"}
+\end{verbatim}
+
+If the document metadata includes \texttt{lof:true}, then the List of
+Figures will use the short caption. This is particularly useful for
+students writing dissertations, who often have to include a List of
+Figures in the front matter, but where figure captions themselves can be
+quite lengthy.
+
+\begin{verbatim}
+pandoc --lua-filter=short-captions.lua article.md -o article.tex
+
+pandoc --lua-filter=short-captions.lua article.md -o article.pdf
+\end{verbatim}
+
+\hypertarget{example}{%
+\section{Example}\label{example}}
+
+Fig.~\ref{fig:shortcap} is an interesting figure with a long caption,
+but a short caption in the List of Figures.
+
+\hypertarget{fig:shortcap}{%
+\begin{figure}
+\centering
+\includegraphics[width=0.5\textwidth,height=\textheight]{fig.pdf}
+\caption[{A short caption with math \(x^n + y^n = z^n\)}]{This is an
+\emph{extremely} interesting figure that has a lot of detail I will need
+to describe in a few sentences. This figure has a short caption that
+will appear in the list of figures. Other attributes are preserved}
+\label{fig:shortcap}
+\end{figure}
+}
+
+\hypertarget{limitations}{%
+\section{Limitations}\label{limitations}}
+
+\begin{itemize}
+\tightlist
+\item
+ The filter will process the \texttt{short-caption} attribute value as
+ pandoc markdown, regardless of the input format.
+\item
+ It does not work for tables and listings yet.
+\item
+ But it works with pandoc-crossref, regardless of the order of
+ application.
+\end{itemize}
diff --git a/paper/lua-filters/short-captions/fig.pdf b/paper/lua-filters/short-captions/fig.pdf
new file mode 100644
index 0000000..cac7f39
--- /dev/null
+++ b/paper/lua-filters/short-captions/fig.pdf
Binary files differ
diff --git a/paper/lua-filters/short-captions/short-captions.lua b/paper/lua-filters/short-captions/short-captions.lua
new file mode 100644
index 0000000..9aaf309
--- /dev/null
+++ b/paper/lua-filters/short-captions/short-captions.lua
@@ -0,0 +1,37 @@
+if FORMAT ~= "latex" then
+ return
+end
+
+local function latex(str)
+ return pandoc.RawInline('latex', str)
+end
+
+function figure_image (elem)
+ local image = elem.content and elem.content[1]
+ return (image.t == 'Image' and image.title == 'fig:')
+ and image
+ or nil
+end
+
+function Para (para)
+ local img = figure_image(para)
+ if not img or not img.caption or not img.attributes['short-caption'] then
+ return nil
+ end
+
+ local short_caption = pandoc.Span(
+ pandoc.read(img.attributes['short-caption']).blocks[1].c
+ )
+ local hypertarget = "{%%\n"
+ local label = "\n"
+ if img.identifier ~= img.title then
+ hypertarget = string.format("\\hypertarget{%s}{%%\n",img.identifier)
+ label = string.format("\n\\label{%s}",img.identifier)
+ end
+ return pandoc.Para {
+ latex(hypertarget .. "\\begin{figure}\n\\centering\n"),
+ img,
+ latex("\n\\caption["), short_caption, latex("]"), pandoc.Span(img.caption),
+ latex(label .."\n\\end{figure}\n}\n")
+ }
+end