Can you create concatenate variable names in LaTex? [duplicate]
up vote
4
down vote
favorite
This question already has an answer here:
Using command parameters to use another command
3 answers
I would like to create variables to hold strings like f(x)=3x+1 to be inputted into an exam questions.
I can create variables like funA, funB, … et cetera. The problem is how do I reference them using A, B, … et cetera.
documentclass[12pt]{exam}
% conditional statements
usepackage{xifthen}
newcommand{exam}{A}
newcommand{funA}{$s(t) = 12t^2 -7t + 16$}
newcommand{funB}{$s(t) = 16t^2 +3t + 10$}
newcommand{funC}{$s(t) = 12t^2 + t + 10.$}
begin{document}
begin{questions}
question % I would like funexam to return funA when exam = a. Sadly it doesn't
The position of an object moving along a straight line is given by funexam. Find the average velocity of the object over the interval $[1,1+h]$ where $h>0$ is a real number.
question % this works but is a lot to write when accommodating 10 stored functions
ifthenelse{equal{exam}{A}}
{
newcommand{function}{$s(t) = 12t^2 -7t + 16.$}
}
{
ifthenelse{equal{exam}{B}}
{
newcommand{function}{$s(t) = 16t^2 +3t + 10.$}
}
{
newcommand{function}{$s(t) = 12t^2 + t + 10.$}
}
}
The position of an object moving along a straight line is given by function Find the average velocity of the object over the interval $[1,1+h]$ where $h>0$ is a real number.
end{questions}
end{document}
variable
marked as duplicate by Werner, Stefan Pinnow, Troy, Kurt, dexteritas yesterday
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
4
down vote
favorite
This question already has an answer here:
Using command parameters to use another command
3 answers
I would like to create variables to hold strings like f(x)=3x+1 to be inputted into an exam questions.
I can create variables like funA, funB, … et cetera. The problem is how do I reference them using A, B, … et cetera.
documentclass[12pt]{exam}
% conditional statements
usepackage{xifthen}
newcommand{exam}{A}
newcommand{funA}{$s(t) = 12t^2 -7t + 16$}
newcommand{funB}{$s(t) = 16t^2 +3t + 10$}
newcommand{funC}{$s(t) = 12t^2 + t + 10.$}
begin{document}
begin{questions}
question % I would like funexam to return funA when exam = a. Sadly it doesn't
The position of an object moving along a straight line is given by funexam. Find the average velocity of the object over the interval $[1,1+h]$ where $h>0$ is a real number.
question % this works but is a lot to write when accommodating 10 stored functions
ifthenelse{equal{exam}{A}}
{
newcommand{function}{$s(t) = 12t^2 -7t + 16.$}
}
{
ifthenelse{equal{exam}{B}}
{
newcommand{function}{$s(t) = 16t^2 +3t + 10.$}
}
{
newcommand{function}{$s(t) = 12t^2 + t + 10.$}
}
}
The position of an object moving along a straight line is given by function Find the average velocity of the object over the interval $[1,1+h]$ where $h>0$ is a real number.
end{questions}
end{document}
variable
marked as duplicate by Werner, Stefan Pinnow, Troy, Kurt, dexteritas yesterday
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
csname funexamendcsname
– Phelype Oleinik
yesterday
I added an answer to the duplicate question.
– egreg
yesterday
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
This question already has an answer here:
Using command parameters to use another command
3 answers
I would like to create variables to hold strings like f(x)=3x+1 to be inputted into an exam questions.
I can create variables like funA, funB, … et cetera. The problem is how do I reference them using A, B, … et cetera.
documentclass[12pt]{exam}
% conditional statements
usepackage{xifthen}
newcommand{exam}{A}
newcommand{funA}{$s(t) = 12t^2 -7t + 16$}
newcommand{funB}{$s(t) = 16t^2 +3t + 10$}
newcommand{funC}{$s(t) = 12t^2 + t + 10.$}
begin{document}
begin{questions}
question % I would like funexam to return funA when exam = a. Sadly it doesn't
The position of an object moving along a straight line is given by funexam. Find the average velocity of the object over the interval $[1,1+h]$ where $h>0$ is a real number.
question % this works but is a lot to write when accommodating 10 stored functions
ifthenelse{equal{exam}{A}}
{
newcommand{function}{$s(t) = 12t^2 -7t + 16.$}
}
{
ifthenelse{equal{exam}{B}}
{
newcommand{function}{$s(t) = 16t^2 +3t + 10.$}
}
{
newcommand{function}{$s(t) = 12t^2 + t + 10.$}
}
}
The position of an object moving along a straight line is given by function Find the average velocity of the object over the interval $[1,1+h]$ where $h>0$ is a real number.
end{questions}
end{document}
variable
This question already has an answer here:
Using command parameters to use another command
3 answers
I would like to create variables to hold strings like f(x)=3x+1 to be inputted into an exam questions.
I can create variables like funA, funB, … et cetera. The problem is how do I reference them using A, B, … et cetera.
documentclass[12pt]{exam}
% conditional statements
usepackage{xifthen}
newcommand{exam}{A}
newcommand{funA}{$s(t) = 12t^2 -7t + 16$}
newcommand{funB}{$s(t) = 16t^2 +3t + 10$}
newcommand{funC}{$s(t) = 12t^2 + t + 10.$}
begin{document}
begin{questions}
question % I would like funexam to return funA when exam = a. Sadly it doesn't
The position of an object moving along a straight line is given by funexam. Find the average velocity of the object over the interval $[1,1+h]$ where $h>0$ is a real number.
question % this works but is a lot to write when accommodating 10 stored functions
ifthenelse{equal{exam}{A}}
{
newcommand{function}{$s(t) = 12t^2 -7t + 16.$}
}
{
ifthenelse{equal{exam}{B}}
{
newcommand{function}{$s(t) = 16t^2 +3t + 10.$}
}
{
newcommand{function}{$s(t) = 12t^2 + t + 10.$}
}
}
The position of an object moving along a straight line is given by function Find the average velocity of the object over the interval $[1,1+h]$ where $h>0$ is a real number.
end{questions}
end{document}
This question already has an answer here:
Using command parameters to use another command
3 answers
variable
variable
edited yesterday
Bernard
163k769192
163k769192
asked yesterday
Garth Fleming
32818
32818
marked as duplicate by Werner, Stefan Pinnow, Troy, Kurt, dexteritas yesterday
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Werner, Stefan Pinnow, Troy, Kurt, dexteritas yesterday
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
csname funexamendcsname
– Phelype Oleinik
yesterday
I added an answer to the duplicate question.
– egreg
yesterday
add a comment |
csname funexamendcsname
– Phelype Oleinik
yesterday
I added an answer to the duplicate question.
– egreg
yesterday
csname funexamendcsname
– Phelype Oleinik
yesterday
csname funexamendcsname
– Phelype Oleinik
yesterday
I added an answer to the duplicate question.
– egreg
yesterday
I added an answer to the duplicate question.
– egreg
yesterday
add a comment |
1 Answer
1
active
oldest
votes
up vote
4
down vote
accepted
TeX allows you to reference c
ontrol s
equence name
s using a csname
...endcsname
pair. Any command inside this csname
...endcsname
pair will be expanded (i.e.: replaced by its meaning) until only unexpandable tokens are left, then TeX creates a control sequence out of the contents passed to csname
...endcsname
.
For instance, if you have newcommand{exam}{A}
, then csname funAendcsname
and csname funexamendcsname
will both expand to funA
. You can create a wrapper command to avoid writing csname
...endcsname
every single time:
documentclass[12pt]{exam}
newcommand{exam}{A}
newcommand{fun}[1]{csname fun#1endcsname}
% or:
% newcommand{fun}{csname funexamendcsname}, then use just fun instead of funexam
newcommand{funA}{$s(t) = 12t^2 -7t + 16$}
newcommand{funB}{$s(t) = 16t^2 +3t + 10$}
newcommand{funC}{$s(t) = 12t^2 + t + 10$}
begin{document}
begin{questions}
question
The position of an object moving along a straight line is given by funexam. Find the average velocity of the object over the interval $[1,1+h]$ where $h>0$ is a real number.
end{questions}
end{document}
LaTeX has@nameuse
but unfortunately it has a@
in its name...
– jfbu
yesterday
@jfbu And there'sexpl3
'suse:c
too, but if you tilt your head to the left it looks too sad ;)
– Phelype Oleinik
yesterday
@jfbu and @PhelypeOleinik: Andetoolbox
'scsuse
, if we're compiling a list :).
– Circumscribe
yesterday
@Circumscribe good point!
– jfbu
yesterday
@PhelypeOleinik you can tilt to your right :)
– jfbu
yesterday
|
show 1 more comment
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
TeX allows you to reference c
ontrol s
equence name
s using a csname
...endcsname
pair. Any command inside this csname
...endcsname
pair will be expanded (i.e.: replaced by its meaning) until only unexpandable tokens are left, then TeX creates a control sequence out of the contents passed to csname
...endcsname
.
For instance, if you have newcommand{exam}{A}
, then csname funAendcsname
and csname funexamendcsname
will both expand to funA
. You can create a wrapper command to avoid writing csname
...endcsname
every single time:
documentclass[12pt]{exam}
newcommand{exam}{A}
newcommand{fun}[1]{csname fun#1endcsname}
% or:
% newcommand{fun}{csname funexamendcsname}, then use just fun instead of funexam
newcommand{funA}{$s(t) = 12t^2 -7t + 16$}
newcommand{funB}{$s(t) = 16t^2 +3t + 10$}
newcommand{funC}{$s(t) = 12t^2 + t + 10$}
begin{document}
begin{questions}
question
The position of an object moving along a straight line is given by funexam. Find the average velocity of the object over the interval $[1,1+h]$ where $h>0$ is a real number.
end{questions}
end{document}
LaTeX has@nameuse
but unfortunately it has a@
in its name...
– jfbu
yesterday
@jfbu And there'sexpl3
'suse:c
too, but if you tilt your head to the left it looks too sad ;)
– Phelype Oleinik
yesterday
@jfbu and @PhelypeOleinik: Andetoolbox
'scsuse
, if we're compiling a list :).
– Circumscribe
yesterday
@Circumscribe good point!
– jfbu
yesterday
@PhelypeOleinik you can tilt to your right :)
– jfbu
yesterday
|
show 1 more comment
up vote
4
down vote
accepted
TeX allows you to reference c
ontrol s
equence name
s using a csname
...endcsname
pair. Any command inside this csname
...endcsname
pair will be expanded (i.e.: replaced by its meaning) until only unexpandable tokens are left, then TeX creates a control sequence out of the contents passed to csname
...endcsname
.
For instance, if you have newcommand{exam}{A}
, then csname funAendcsname
and csname funexamendcsname
will both expand to funA
. You can create a wrapper command to avoid writing csname
...endcsname
every single time:
documentclass[12pt]{exam}
newcommand{exam}{A}
newcommand{fun}[1]{csname fun#1endcsname}
% or:
% newcommand{fun}{csname funexamendcsname}, then use just fun instead of funexam
newcommand{funA}{$s(t) = 12t^2 -7t + 16$}
newcommand{funB}{$s(t) = 16t^2 +3t + 10$}
newcommand{funC}{$s(t) = 12t^2 + t + 10$}
begin{document}
begin{questions}
question
The position of an object moving along a straight line is given by funexam. Find the average velocity of the object over the interval $[1,1+h]$ where $h>0$ is a real number.
end{questions}
end{document}
LaTeX has@nameuse
but unfortunately it has a@
in its name...
– jfbu
yesterday
@jfbu And there'sexpl3
'suse:c
too, but if you tilt your head to the left it looks too sad ;)
– Phelype Oleinik
yesterday
@jfbu and @PhelypeOleinik: Andetoolbox
'scsuse
, if we're compiling a list :).
– Circumscribe
yesterday
@Circumscribe good point!
– jfbu
yesterday
@PhelypeOleinik you can tilt to your right :)
– jfbu
yesterday
|
show 1 more comment
up vote
4
down vote
accepted
up vote
4
down vote
accepted
TeX allows you to reference c
ontrol s
equence name
s using a csname
...endcsname
pair. Any command inside this csname
...endcsname
pair will be expanded (i.e.: replaced by its meaning) until only unexpandable tokens are left, then TeX creates a control sequence out of the contents passed to csname
...endcsname
.
For instance, if you have newcommand{exam}{A}
, then csname funAendcsname
and csname funexamendcsname
will both expand to funA
. You can create a wrapper command to avoid writing csname
...endcsname
every single time:
documentclass[12pt]{exam}
newcommand{exam}{A}
newcommand{fun}[1]{csname fun#1endcsname}
% or:
% newcommand{fun}{csname funexamendcsname}, then use just fun instead of funexam
newcommand{funA}{$s(t) = 12t^2 -7t + 16$}
newcommand{funB}{$s(t) = 16t^2 +3t + 10$}
newcommand{funC}{$s(t) = 12t^2 + t + 10$}
begin{document}
begin{questions}
question
The position of an object moving along a straight line is given by funexam. Find the average velocity of the object over the interval $[1,1+h]$ where $h>0$ is a real number.
end{questions}
end{document}
TeX allows you to reference c
ontrol s
equence name
s using a csname
...endcsname
pair. Any command inside this csname
...endcsname
pair will be expanded (i.e.: replaced by its meaning) until only unexpandable tokens are left, then TeX creates a control sequence out of the contents passed to csname
...endcsname
.
For instance, if you have newcommand{exam}{A}
, then csname funAendcsname
and csname funexamendcsname
will both expand to funA
. You can create a wrapper command to avoid writing csname
...endcsname
every single time:
documentclass[12pt]{exam}
newcommand{exam}{A}
newcommand{fun}[1]{csname fun#1endcsname}
% or:
% newcommand{fun}{csname funexamendcsname}, then use just fun instead of funexam
newcommand{funA}{$s(t) = 12t^2 -7t + 16$}
newcommand{funB}{$s(t) = 16t^2 +3t + 10$}
newcommand{funC}{$s(t) = 12t^2 + t + 10$}
begin{document}
begin{questions}
question
The position of an object moving along a straight line is given by funexam. Find the average velocity of the object over the interval $[1,1+h]$ where $h>0$ is a real number.
end{questions}
end{document}
answered yesterday
Phelype Oleinik
21k54380
21k54380
LaTeX has@nameuse
but unfortunately it has a@
in its name...
– jfbu
yesterday
@jfbu And there'sexpl3
'suse:c
too, but if you tilt your head to the left it looks too sad ;)
– Phelype Oleinik
yesterday
@jfbu and @PhelypeOleinik: Andetoolbox
'scsuse
, if we're compiling a list :).
– Circumscribe
yesterday
@Circumscribe good point!
– jfbu
yesterday
@PhelypeOleinik you can tilt to your right :)
– jfbu
yesterday
|
show 1 more comment
LaTeX has@nameuse
but unfortunately it has a@
in its name...
– jfbu
yesterday
@jfbu And there'sexpl3
'suse:c
too, but if you tilt your head to the left it looks too sad ;)
– Phelype Oleinik
yesterday
@jfbu and @PhelypeOleinik: Andetoolbox
'scsuse
, if we're compiling a list :).
– Circumscribe
yesterday
@Circumscribe good point!
– jfbu
yesterday
@PhelypeOleinik you can tilt to your right :)
– jfbu
yesterday
LaTeX has
@nameuse
but unfortunately it has a @
in its name...– jfbu
yesterday
LaTeX has
@nameuse
but unfortunately it has a @
in its name...– jfbu
yesterday
@jfbu And there's
expl3
's use:c
too, but if you tilt your head to the left it looks too sad ;)– Phelype Oleinik
yesterday
@jfbu And there's
expl3
's use:c
too, but if you tilt your head to the left it looks too sad ;)– Phelype Oleinik
yesterday
@jfbu and @PhelypeOleinik: And
etoolbox
's csuse
, if we're compiling a list :).– Circumscribe
yesterday
@jfbu and @PhelypeOleinik: And
etoolbox
's csuse
, if we're compiling a list :).– Circumscribe
yesterday
@Circumscribe good point!
– jfbu
yesterday
@Circumscribe good point!
– jfbu
yesterday
@PhelypeOleinik you can tilt to your right :)
– jfbu
yesterday
@PhelypeOleinik you can tilt to your right :)
– jfbu
yesterday
|
show 1 more comment
csname funexamendcsname
– Phelype Oleinik
yesterday
I added an answer to the duplicate question.
– egreg
yesterday