Skip to content

Commit a52aa6c

Browse files
committed
feat(inkscape): automatic composition of watermark string
Signed-off-by: Jonas Dujava <[email protected]>
1 parent 2b8f675 commit a52aa6c

4 files changed

Lines changed: 27 additions & 15 deletions

File tree

chapters/Appendix.tex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ \chapter{Example of Appendix Chapter} \label{appendix:example}
77
\end{example}
88

99
\begin{figure}[!ht]
10+
\exportInkscapeSVG{parallel-plate-capacitor}% export already here, such that we can use it in the caption
1011
\fcapside[\FBwidth]{%
1112
\caption[Example of a figure with a side-caption.]{
1213
Example of a figure with a side-caption.
@@ -23,7 +24,7 @@ \chapter{Example of Appendix Chapter} \label{appendix:example}
2324
}%
2425
\label{fig:parallel-plate-capacitor}%
2526
\floatfoot{You can also optionally use a footnote\\ for the figure caption.}%
26-
}{\includegraphics[width=0.6\textwidth]{parallel-plate-capacitor}}
27+
}{\includeInkscapeSVG[0.6\textwidth]{parallel-plate-capacitor}}%
2728
\end{figure}
2829
\begin{figure}[!ht]
2930
\ffigbox[\FBwidth]{%

chapters/Features.tex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -476,17 +476,17 @@ \subsection{\texorpdfstring{\texttt{Inkscape}}{Inkscape} Integration}%
476476
\label{sub:Inkscape Integration}
477477
\fileTeXtured{preamble/misc/inkscape.tex}
478478

479+
Put your \texttt{Inkscape} figures into \path{figures/Inkscape/} directory, and include them using \custommacro{\includeInkscapeSVG} macro (in place of \macro{\includegraphics}), which has the following features:
479480
\begin{itemize}
480-
\item automatic export after changing the \texttt{svg} (need to enable \macro{--shell-escape} for \hologo{pdfTeX} or \hologo{LuaTeX}, done via \path{.latexmkrc})
481-
\item watermark via \texttt{ps} injection
481+
\item Automatic export after changing the \texttt{svg} (need to enable \macro{--shell-escape} for \hologo{pdfTeX} or \hologo{LuaTeX}, done via \path{.latexmkrc}).
482+
\item Watermark via a \texttt{PostScript} injection.
482483
\begin{remark}[Watermark String]
483-
Edit the watermark text in the shell script \path{figures/Inkscape/inkscape-export-to-latex} to your liking.
484+
By default, the watermark string is composed as \enquote{\copyright \textlangle\textit{year}\textrangle{} \textlangle\textit{author's name}\textrangle}, where the author's name is extracted from \custommacro{\ThesisAuthorPlaintext}.
485+
You can customize it in the shell script \path{figures/Inkscape/inkscape-export-to-latex} to your liking.
484486
\end{remark}
485-
\begin{Todo}
486-
Make it easier to change the watermark text.
487-
Or extract it somehow automatically from the PDF document?
488-
\end{Todo}
489-
\item automatic fix of \macro{/Interpolation} key problem
487+
\item Automatic fix of \macro{/Interpolation} key problem.
488+
\item All text is processed by \LaTeX{}, ensuring consistent typesetting experience.
489+
In particular, you can enter math as usual through \macro{$...$}.
490490
\end{itemize}
491491

492492

figures/Inkscape/inkscape-export-to-latex

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,22 @@
77
inkscape "$1.svg" --export-area-drawing --export-dpi=300 --export-latex --export-filename="$1.pdf"
88

99
## Disable interpolation in the PDF (to conform with PDF/A standard)
10-
# sed -i 's|/Interpolate true$|/Interpolate false|' "$1.pdf" # SOMETIMES BORKS THE PDF
10+
# sed -i 's|/Interpolate true$|/Interpolate false|' "$1.pdf" # sometimes CORRUPTS the PDF
1111
## https://stackoverflow.com/questions/20011515/how-to-remove-anti-aliasing-in-pdf-images
1212
perl -M-encoding -0777pe "s|/Interpolate true|' 'x17|ge" <"$1.pdf" >"$1-fixed.pdf"
1313

1414
## Add watermark to the PDF (if watermark script is available)
1515
directory=$(dirname "$1")
1616
if [ -f "$directory/add-watermark" ]; then
17-
## NOTE: edit the watermark string here
18-
watermark_string="$(date +%Y) Jonas Dujava"
17+
## try to extract the author's name from the LaTeX preamble
18+
author_name=$(sed -n 's/^[^%].*ThesisAuthorPlaintext}{}{\(.*\)}$/\1/p' preamble/data.tex)
19+
## if the `\ThesisAuthorPlaintext` command is commented out, extract from the `\ThesisAuthor` command
20+
[ -z "$author_name" ] && author_name=$(sed -n 's/.*ThesisAuthor}{}{\(.*\)}$/\1/p' preamble/data.tex)
21+
22+
author_name=$(printf "%s" "$author_name" | iconv -f utf8 -t ascii//TRANSLIT) # use just ASCII characters
23+
watermark_string="$(date +%Y) $author_name" # prepend the year
24+
25+
# watermark_string="$(date +%Y) Author's Name" ## NOTE: or manually edit the watermark string here
1926
"$directory"/add-watermark "$1-fixed.pdf" "$watermark_string"
2027
fi
2128

preamble/misc/inkscape.tex

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
%% TODO: disable this for ArXiv submission (probably just leaving SVGs out will work fine)
55
\usepackage{shellesc}
66
\usepackage{filemod}
7-
\NewDocumentCommand{\includesvg}{O{0.8\linewidth} O{./figures/Inkscape/} m}{%
8-
\filemodCmp{#2#3.pdf}{#2#3.svg}{}{% regenerate PDF+LaTeX code if SVG is newer
9-
\ShellEscape{#2inkscape-export-to-latex "#2#3"}% use `inkscape-export-to-latex` script in the same directory
7+
\NewDocumentCommand{\exportInkscapeSVG}{O{./figures/Inkscape/} m}{%
8+
\filemodCmp{#1#2.pdf}{#1#2.svg}{}{% regenerate PDF+LaTeX code if SVG is newer
9+
\ShellEscape{#1inkscape-export-to-latex "#1#2"}% use `inkscape-export-to-latex` script in the same directory
1010
}%
11+
}
12+
%% the third argument is the name of the SVG file without the extension
13+
\NewDocumentCommand{\includeInkscapeSVG}{O{0.8\linewidth} O{./figures/Inkscape/} m}{%
14+
\exportInkscapeSVG[#2]{#3}%
1115
\def\svgwidth{#1}% set the width of the figure
1216
\input{#2#3.pdf_tex}%
1317
}

0 commit comments

Comments
 (0)