
Tenho algumas imagens que preciso cortar e outras para cortar. Implementei uma única solução usando duas \newcommand
que funcionaram, mas procuro uma solução compacta usando xparse que não funcionou e não consigo entender o porquê.
Agradeço qualquer ajuda para corrigir e melhorar meu código abaixo.
\documentclass[11pt]{article}
\usepackage{easyfig}
% [cut up]{file}{caption}{label}{scale} - Cut up % <== Ok
\newcommand{\ruleone}[5][.05]{%
\Figure[trim={.0\width} {.0\height} {.0\width} {#1\height},clip,%
width=#5\linewidth,keepaspectratio=true,%
caption={#3},label={#4},center,here]{#2}
}
% [cut down]{file}{caption}{label}{scale} - Cut down % <== Ok
\newcommand{\ruletwo}[5][.05]{%
\Figure[trim={.0\width} {#1\height} {.0\width} {.0\height},clip,%
width=#5\linewidth,keepaspectratio=true,%
caption={#3},label={#4},center,here]{#2}
}
% [cut up]{file}[cut down]{caption}{label}[scale] - Cut down % <== compile with errors
\newcommand{\onerule}[ o m o m m o ]{%
\Figure[trim={.0\width} {ifNoValueTF{#1}{.0}{#1}\height}%
{.0\width} {ifNoValueTF{#3}{.0}{#3}\height},clip,%
width={ifNoValueTF{#6}{1}{#6}\linewidth},keepaspectratio=true,%
caption={#4},label={#5},center,here]{#2}
}
\begin{document}
Here comes the images:
\ruleone[.45]{example-image-a}{First image}{label1}{.5} % <== this works
\ruletwo[.35]{example-image-a}{Second image}{label2}{.5} % <== This too
\onerule[.35]{example-image-b}{Third image}{label3}{.5}
\onerule{example-image-b}[0.45]{Third image}{label3}{.5}
\end{document}
Responder1
Em xparse
, o comando para definir novos comandos é \NewDocumentCommand
em vez de \newcommand
. Além disso, o segundo argumento que descreve os parâmetros é obrigatório ( {...}
em vez de [...]
) e ifNoValueTF
deve ser \IfNoValueTF
(maiúsculo e com barra invertida).
Além disso, o %
argumento no final da linha com trim suprime um espaço obrigatório e o argumento scale é opcional ( [...]
em vez de {...}
).
Então você consegue
\documentclass[11pt]{article}
\usepackage{xparse,easyfig}
% [cut up]{file}{caption}{label}{scale} - Cut up % <== Ok
\newcommand{\ruleone}[5][.05]{%
\Figure[trim={.0\width} {.0\height} {.0\width} {#1\height},clip,%
width=#5\linewidth,keepaspectratio=true,%
caption={#3},label={#4},center,here]{#2}
}
% [cut down]{file}{caption}{label}{scale} - Cut down % <== Ok
\newcommand{\ruletwo}[5][.05]{%
\Figure[trim={.0\width} {#1\height} {.0\width} {.0\height},clip,%
width=#5\linewidth,keepaspectratio=true,%
caption={#3},label={#4},center,here]{#2}
}
% [cut up]{file}[cut down]{caption}{label}[scale] - Cut down % <== compile with errors
\NewDocumentCommand \onerule { o m o m m o }{%
\Figure[trim={.0\width} {\IfNoValueTF{#1}{.0}{#1}\height}
{.0\width} {\IfNoValueTF{#3}{.0}{#3}\height},clip,%
width={\IfNoValueTF{#6}{1}{#6}\linewidth},keepaspectratio=true,%
caption={#4},label={#5},center,here]{#2}
}
\begin{document}
Here comes the images:
\ruleone[.45]{example-image-a}{First image}{label1}{.5} % <== this works
\ruletwo[.35]{example-image-a}{Second image}{label2}{.5} % <== This too
\onerule[.35]{example-image-b}{Third image}{label3}[.5]
\onerule{example-image-b}[0.45]{Third image}{label3}[.5]
\end{document}