I am trying to create a new command to help formatting the entries of the list of figures. Argument 1 should be optional and contain the date the source was accessed, argument 2 is simply the figure's caption I want to show up in the list of figures, and argument 3 is a hyperlink to the source of the image. I want the source and date to only show up in the list of figures and not underneath the actual image. I wrote this in the preamble:
\newcommand{\lof}[3][]{
\textbf{#2}
\linebreak
{\scriptsize #3 #1}
}
This is the caption of some figure:
\caption[
\lof[(Accessed on 02.01.2019)]
{Basic neural network with three layers}
{\url{https://commons.wikimedia.org/wiki/File:Artificial_neural_network.svg}}
]
{Basic neural network with three layers}
Note that I want to be able to declare that the image is my own, in which case the hyperlink and the date should be omitted.
\caption[
{Basic neural network with three layers}
{Made by the author.}
]
{Basic neural network with three layers}
This gives me the following error:
! Argument of \\lof has an extra }.
However, the brackets should be balanced if I am not completely mistaken. I have read somewhere that there are 'fragile' commands, and using them leads to the same error message I got. Might \url{} be a fragile command? Or have I messed up the command definition somehow?
Edit:
The following code shows everything that might be related to the problem. If I remove these parts from the code, the LaTeX documents compiles.
\documentclass{article}
\usepackage{wrapfig,graphicx,amsmath,hyperref}
\newcommand{\lof}[3][]{\textbf{#2}\newline {\scriptsize #3 #1}}
\begin{document}
\listoffigures
\begin{wrapfigure}{r}{0.25\textwidth}
\centering
\includegraphics[width=0.25\textwidth]{example-image}
\caption[ {\lof[(Accessed on 02.01.2019)]
{Basic neural network with three layers}
{\url{https://commons.wikimedia.org/wiki/File:Artificial_neural_network.svg}}} ]
{Basic neural network with three layers}
\label{fig:nn}
\end{wrapfigure}
\begin{wrapfigure}{h}{0.5\textwidth}
\centering
\includegraphics[width=0.5\textwidth]{example-image}
\caption[{\lof{$\boldsymbol{\sigma (x)}$, the sigmoid function}
{Created by the author}}]
{$\sigma (x)$, the sigmoid function}
\label{fig:sigmoid}
\end{wrapfigure}
\end{document}
\caption[ {\lof[(Accessed on 02.01.2019)] {Basic neural network with three layers} {\url{https://commons.wikimedia.org/wiki/File:Artificial_neural_network.svg}}} ] {Basic neural network with three layers}
-- you must enclose the\lot[...]{}{}
command with a{}
pair, since it has an optional argument and occurs in the optional argument of\caption
xparse
package, which makes it considerably easier to define commands with multiple optonal arguments.