Math & ScienceInserting a mathematics expression into an equation

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
nabufe86
Posts: 5
Joined: Sat Jul 19, 2014 10:21 pm

Inserting a mathematics expression into an equation

Post by nabufe86 »

Hi all,

I am not 100% sure if this is the best forum to post this question in but none of them fit perfectly.

I have the following problem. I would like to assemble a document with a bunch of variables and equations. In that document I would like to:
1) use dummy names for variables rather than typing symbols and 2) be able to adjust symbols later and have them change consistently in the entire document.

What I tried to do is make a list at the beginning of the document with \newcommand{\dumyname}{symbol} (c.f. MWE below). Then have a section with all the symbols in a table. The example is here:

Code: Select all

\documentclass[12pt]{article}
% define the title
\usepackage{amsmath}
%load math package
\author{NA. Bufe}
\title{Some equations}

\begin{document}
% generates the title
\maketitle
% insert the table of contents
\tableofcontents
\newpage

%% -------define new comands--------
\newcommand{\waterheight}{$h_w$}
\newcommand{\sediheight}{$h_s$}


%% -------Section 1 - Symbols-------- 
\section*{Symbols}
\begin{tabular}{l l}
\waterheight &Water depth ($m$)\\ 
\sediheight &Sediment thickness ($m$)\\
\end{tabular}
\end{document}
That code works fine. The reason to use mathematical expressions in the definition of the variables instead of \textsubscript is because typing "$...$" is faster and also in order to have a consistent font (the mathematics font). The problem then arises when I try to add the variables to an equation. Such as:

Code: Select all

\begin{equation}
x+y = \sediheight
\end{equation}
I believe that the reason for the problem is that \sediheight is referring to a mathematical expression and I cannot add that within an equation.

I was just wondering whether 1) there is some way to get methematical expressions into an equation or 2) there is another smart way around this.

The reason for this setup is as I said, that I would like to be able to change the symbology later in one place (at the beginning of the document) and then it consistently changes the symbol in all the equations that contain it and in the list of symbols. In addition I find it sometimes faster to type the dummy names then to type complicated symbols (those examples aren't very complicated but others might be).

I hope that this question is somewhat clear. Thanks for the help already!

Best wishes

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
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Inserting a mathematics expression into an equation

Post by Johannes_B »

Disclaimer: I didn't read your entire post, it is late here.

I think you are looking for the \ensuremath command.

But package glossaries can help you a lot with this. There are examples for your use-case in the package documentation. It also prints out a list of Symbols (or whatever you want to call it).

I might have some time tomorrow and provide a MWE, but i can't promise.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
nabufe86
Posts: 5
Joined: Sat Jul 19, 2014 10:21 pm

Re: Inserting a mathematics expression into an equation

Post by nabufe86 »

Yesssss!! \ensuremath works!

I am not sure I understand why it works but it does :D

Thanks a lot. I might also look at the glossary. Maybe that is easier.
Post Reply