¿Romper los argumentos del nuevo comando con '/' para un uso diferente?

¿Romper los argumentos del nuevo comando con '/' para un uso diferente?

Estoy creando una presentación con muchos marcos con una figura por diapositiva. Entonces, en lugar de tener cientos del mismo código una y otra vez, creé un \newcommandcódigo simple donde uno de los argumentos es el nombre de la figura, que también uso como etiqueta para la figura. Pero cuando uso subcarpetas de figuras, el argumento es: subfolderone/subfoldertwo/figurename. Pero solo quiero usarlo figurenamecomo etiqueta de figura.

¿Es posible dividir el argumento n.° 1 con "/" y usar solo el último para etiquetar? De lo contrario... simplemente haré otro argumento de entrada.

\documentclass{beamer}
\usepackage{graphicx}

\newcommand{\figcaptiontitlecrop}[7]{%
    \begin{frame}[b]{#3}
        \begin{figure}
            \centering
            \includegraphics[trim=#4mm #5mm #6mm #7mm, clip]{#1}
            \caption{#2}%
            \label{fig:#1}%
        \end{figure}
    \end{frame}
}

\begin{document}
\figcaptiontitlecrop{filename}{Caption Text}{Frame Title Here}{0}{0}{0}{0}
%\figcaptiontitlecrop{figures/subfolder/filename}{Caption Text}{Frame Title Here}{0}{0}{0}{0}
\end{document}

Respuesta1

Se debe evitar un comando con siete argumentos. Un enfoque de valor clave es mejor:

\documentclass{beamer}
\usepackage{graphicx}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\beamerfigure}{mm}
 {
  \begin{frame}[b]
  \keys_set:nn { bjartmar/beamerfigure } { #1 }
  \frametitle{\l_bjartmar_beamerfigure_title_tl}
  \begin{figure}
    \centering
    \use:x
     {
      \exp_not:N \includegraphics [
        \l_bjartmar_beamerfigure_options_tl,
        trim=\l_bjartmar_beamerfigure_tl,
        clip
      ]
    }{\l_bjartmar_beamerfigure_path_tl / \l_bjartmar_beamerfigure_name_tl}
    \caption{#2}
    \label{fig:\l_bjartmar_beamerfigure_name_tl}
    \end{figure}
  \end{frame}
}
\keys_define:nn { bjartmar/beamerfigure }
 {
  title   .tl_set:N  = \l_bjartmar_beamerfigure_title_tl,
  path    .tl_set:N  = \l_bjartmar_beamerfigure_path_tl,
  path    .initial:n = {.},
  name    .tl_set:N  = \l_bjartmar_beamerfigure_name_tl,
  options .tl_set:N  = \l_bjartmar_beamerfigure_options_tl,
  trim    .tl_set:N  = \l_bjartmar_beamerfigure_tl,
  trim    .initial:n = 0~0~0~0,
 }
\ExplSyntaxOff

\begin{document}

\beamerfigure{
  name=donald-duck,
  options={height=.5\textheight},
  trim=0 5 0 5,
}{This is Donald Duck}

\beamerfigure{
  path=/usr/local/texlive/2016/texmf-dist/tex/latex/mwe/,
  name=example-grid-100x100pt,
}{Another figure}

\end{document}

Si no pathse especifica, se utiliza el directorio actual. Como puede ver, también puede especificar opciones adicionales para \includegraphics.

ingrese la descripción de la imagen aquí

información relacionada