Math & Science[SOLVED] use string variables

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
BastienBastien
Posts: 40
Joined: Mon Aug 20, 2012 2:27 pm

[SOLVED] use string variables

Post by BastienBastien »

Hello LaTeX users,
Do you know whether it is possible to use "string variables"
to simplify some LaTeX code. For instance, one could write
something that looks like:

Code: Select all

STR1 = "\alpha+\beta"
STR2 = "\gamma bla bla bla"
STR3 = "Hello this is a complex equation!"
STR4 = "Please help me guys!!!!"

\begin{tabular}{|c|c|}
	\hline 
STR1	&  STR2\\ 
	\hline 
STR3	&  STR4\\ 
	\hline 
\end{tabular}
So that the big tabular is easier to modify, read.

Thanks,
Regards,
Bastien
Last edited by BastienBastien on Mon Dec 25, 2017 9:52 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10322
Joined: Mon Mar 10, 2008 9:44 pm

[SOLVED] use string variables

Post by Stefan Kottwitz »

Hi Bastien!

That is a fundamental property of LaTeX: string macros. I'm sure you saw it already:

\newcommand{\mystr}{hello}

Then use \mystr in the text. You can have many such macros, and you can build macros of macros. But names can only contain letters, uppercase and lowercase, no numbers.

Stefan
LaTeX.org admin
BastienBastien
Posts: 40
Joined: Mon Aug 20, 2012 2:27 pm

use string variables

Post by BastienBastien »

Hi Stefan,

Yep for sure and I even use it a little bit.
But I though may be there is something more suitable to such usage.
Ok thanks I'll use this command.

Regards,
Bastien
User avatar
Stefan Kottwitz
Site Admin
Posts: 10322
Joined: Mon Mar 10, 2008 9:44 pm

[SOLVED] use string variables

Post by Stefan Kottwitz »

Yes, it looks different to a simple Str="...", as it's classic LaTeX syntax. But it serves exactly the purpose, looks the same in the text except the backslash.

Stefan
LaTeX.org admin
BastienBastien
Posts: 40
Joined: Mon Aug 20, 2012 2:27 pm

use string variables

Post by BastienBastien »

Thanks Stefan!
Post Reply