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?

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

1 Answer 1

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.

2
  • So is there any alternative? Or is there no way around copy/paste in this instance?
    – argentum2f
    Commented Mar 29, 2019 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} Commented Mar 29, 2019 at 21:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .