LaTeX forum ⇒ Math & Science[SOLVED] use string variables Topic is solved

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

[SOLVED] use string variables

Postby BastienBastien » Fri Dec 22, 2017 11:23 pm

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:

  1. STR1 = "\alpha+\beta"
  2. STR2 = "\gamma bla bla bla"
  3. STR3 = "Hello this is a complex equation!"
  4. STR4 = "Please help me guys!!!!"
  5.  
  6. \begin{tabular}{|c|c|}
  7. \hline
  8. STR1 & STR2\\
  9. \hline
  10. STR3 & STR4\\
  11. \hline
  12. \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.

Tags:

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

Postby Stefan Kottwitz » Sat Dec 23, 2017 2:49 am

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
Site admin

BastienBastien
Posts: 40
Joined: Mon Aug 20, 2012 2:27 pm

Postby BastienBastien » Sat Dec 23, 2017 11:54 am

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: 8792
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Sat Dec 23, 2017 4:49 pm

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
Site admin

BastienBastien
Posts: 40
Joined: Mon Aug 20, 2012 2:27 pm

Postby BastienBastien » Mon Dec 25, 2017 9:51 pm

Thanks Stefan!


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 3 guests