last day (14 days later) » 

12:09 AM
2
Q: Expansion for Macro to pass to scaleBox

tedI am trying to calculate some width in a macro and use the macro for scalebox. However I get a flood of errors when I try to pass the macro to scalebox. MinimalExample: \documentclass{article} \usepackage{pgf} \newcounter{Counter} \setcounter{Counter}{1} \newcommand{\testOk}{1} \newcommand{\...

 
\scalebox needs a number but you have passed it instructions to typeset a counter and then do some arithmetic to add 1 and assign that value to a counter, that is never going to work, you need to do the arithmetic fist then pass in the value.
 
ted
@DavidCarlisle: I am trying to write a small package to solve my old problem tex.stackexchange.com/a/125722/19326. The idea is to automatically do some calculation and retireve the result to pass it to a scaling package like scalebox or adjustbox. I need csname for the retrival.
 
yes but as Steven shows below you need to pass the result not instructions to execute some arithmetic and assignments. internally it is count@=#1 which is fine if #1 is a number but if you pass it \the\mycount\relax \advance\mycount by 1 then it doesn't work.
The update code is missing loads of % from ends of lines, and if I understand you correctly you are passing tokens including \setcounter and \PackageWarning into the first argument which will put them in an \edef those commands can not possibly work in that context. The first argument of \scalebox is already expanded by \scalebox anything that you could put in an \edef can be passed as the argument to \scalebox so your redefinition does not do anything other than add spaces to the output.
 
ted
@egreg: I am trying to wrap tex.stackexchange.com/a/125722/19326 into a package. The idea is to have an environment where I can do \addImage{someCode} to add an image and \getScale to get the factor by which the image should be scaled so that all pictures fill the row, and have equal height while keeping aspect ratios. I would like these two command so adjustbox scalbox or tikzscale can be used, depending on the situation. Take a look at github.com/coderinside/imageRow tp see what I got so far.
@DavidCarlisle I think I still have to get my head around tex, I am thinking a little bit in c-style here so to me int func{return 2;} and int func{int i=getOneSomehow(); return i+1;} are equal in the outcome of the program.
So is there someway that i can take an arbitrary defined command, execute it once and store its return in a way that it is save to pass to scalebox?
 
@ted tex is a macro expansion language so more like the c pre-processor than C, the analogy is not putttting a function there that returns an integer its like, in fact is putting a macro their that inlines the body of the function, That wouldn't work in c either in general
 
ted
12:09 AM
@DavidCarlisle regarding the missing %, I tried it out, the % is the minimum amount to have no extrawhitespace in the output. If I do \getIt\getIt I get two numbers with no space in between, e.g. 1.2349.034 (notice the second decimal dot, with space it would be 1.234 9.034)
 
@ted there is no return it os a macro language not a functional language, if you macro leaves a value in a register or another macro, then you can pass in that result, but in general there is no result or return from an arbitrary macro
 
ted
Sorry about making you awnser twice but I was typing my second comment while your first came up
but if understand you correctly I could do somthing like:
\renewcommand{\scalebox}[2]{
\ifx#1\getIt
\oldScalebox{\tmpValue}{##2}
}
sry that is incomplete
 
@ted possibly (if you add the missing % and \else and \fi and if #1 is only ever a single token, and you add some code to define `\tmpvalue in the then and else branches
but why redefine scalebox rathe rthan just define a new command (which is 1000 times safer)
 
ted
well i had some trouble getting the newline stuff in chat
but that is the idea
well my idea is the following:
 
@ted trick is to write multiline text somewhere else in an editor then paste it in and a "fixed format" button appears
 
ted
12:16 AM
shift+enter works as well
 
1
2
3
@ted yes true it's stupidly counter-intuitive either way;-)
 
ted
back to the idea: I have mutliple images in a row and want to make them all to have the same height
and scale them so that in total they fill for instance \linewidth
now the user might want to choose different scaling alternatives
i.e. scalebox tikzscale or adjustbox
 
@ted why?
 
ted
Why what?
WHy different tools for scaling?
 
@ted they all are the same thing
 
ted
12:19 AM
well one is different
 
ted
tikzscale
while the others scale the whole image
tikz scales the image but leaves the labels at fontsize
so if you draw an rectangle and label the corners, you scale the rectangle but the labels still have textsize
but maybe I jsut define two commands then
one for scalebox and one for tikzscale
 
@ted yes but only because tikz isn't an image, it's text. If you have external images then scaling is the only option
 
ted
I think you helped me a lot
I believe I have a slightly better knowledge of the issues (still I do not quite understand why it is impossible to wrap some commands in others)
and I think if I offer both solutions (I usually work with Tikz, but sometimes I have Images too, so it should be fine
@DavidCarlisle the only last question is is
\newenviornmen{myenv}{\begingroup\newcommand{}
}{\endgroup}

the right way to constrain my commands to the enviornment, or is there a better practice (they should be only available inside the enviornment)
 
for your oringinal problem don't you just want to make your row of images scaled to same height, then scale the row as a unit? that is \resizebox{\textwith}{!}{\includegraphics[height=1cm]{q}\quad\includegraphics[h‌​eight=1cm]{b}\quad\includegraphics[height=1cm]{zz}}
@ted \begingroup \endgroup aren't doing anything environments are a group
@ted and you need a % after the {}
 
ted
12:37 AM
@DavidCarlisle Well I have never looked at it that way. So the only argument I would have for my solution is Tikzscale, where your solution won't work.

Does scaling incur a qualtiy loss in tex? (I assume not or are the boxes rendered inbetween? i.e. if i scale a huge image down to 1 cm and then scale it up again to 1m will there be a difference between this version and a version where I scale the picture directly to 1m?
 
@ted probably not although it's out of latex's control, the scaling happens in the back end, although similar concerns mean that \includegraphics actually uses two version of scaling for most back ends, if you just go [height= or scale= it passes the required scale factor to the back end as part of the image inclusion if the driver has that facility for that type, if it hasn't or if you have gone [angle=90] or other things as well as scaling then internally....
.... scalebox is used so the back end gets three calls instead of one, scale, image include, scale restore, I never new whether this made any difference in practice but it seemed the right thing to do at the time.
 

last day (14 days later) »