0

I have a bunch of images to include and want to use the same clip parameters on them. The approach I'm taking doesn't seem to work though:

This works:

\includegraphics[clip,trim=0 0 80px 80px, width=\x\textwidth]{image}   

This doesn't:

\newcommand\x{.22}
\newcommand\mytrim{0 0 80px 80px}
\includegraphics[clip,trim=\mytrim, width=\x\textwidth]{image}
                            ^              ^- Does work
                            ^- Doesn't work

What am I doing wrong?

  • How about \newcommand\exchange[2]{#2#1}\expandafter\exchange\expandafter{\mytrim}{\includegraphics[clip, trim=}, width=\x\textwidth]{image} ? – Ulrich Diez Mar 30 '19 at 13:59
1

the syntax 0.5\textwidth is built in to tex so a length setting of \x\textwidth where \x is a factor such as 0.5 just works naturally, however the macros behind trim key needs to parse the space separated list "by hand" and \mytrim doesn't have any spaces until it is expanded.

| improve this answer | |
  • So is there any alternative? Or is there no way around copy/paste in this instance? – argentum2f Mar 29 '19 at 21:15
  • @argentum2f oh lots of things you could do but you provided very little context and no test file, you could do \newcommand\zz[1]{\includegraphics[clip,trim=0 0 80px 80px, width=.22\textwidth]{#1} for example then \zz{image1} \zz{image2} – David Carlisle Mar 29 '19 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.