I have two files math.sty and matlab.sty. I want to define for example the power operation in the two with the same name (it is important that they have exactly the same name for the use that I have to give the files later) and invoke them in the same document. But when it's called, it raises an error. For example:
maths.sty contains:
\newcommand\power{ Power is a mathematical operation that is
represented with a superscript: $5^3$.}
and matlab.sty contains
\newcommand\power{ In matlab the power is written with the symbol $
\^{} $}
Is there any alternative to newcommand
?
UPDATE:
The files math.sty and matlab.sty have many definitions. Also, I have to add the files mathUSER.sty and matlabUSER.sty.
I want to have all the definitions available for use in a template. And these new commands have to be written in a simple way so that children can use them without problem and create their own commands.
I have written all definitions in dictionary.sty
. I would like to separate these definitions in matlab.sty, maths.sty, matlabuser.sty and mathsuser.sty.
\newcommand\dictionary[2]{
\IfEqCase{#1}{
{matlab}{\matlab{#2}}
{maths}{\maths{#2}}
{matlabuser}{\matlabuser{#2}}
{mathsuser}{\mathsuser{#2}}
}
}
\newcommand\matlab[1]{
\IfEqCase{#1}{
{abs}{The absolute the absolute value in programming...}
{addition}{The addition ...}
}
}
\newcommand\maths[1]{
\IfEqCase{#1}{
{addition}{The addition in maths...}
...
}
}
\newcommand\matlabuser[1]{ \IfEqCase{#1}{
...
}
}
\newcommand\mathsuser[1]{ \IfEqCase{#1}{
...
}
}
Invoke: \dictionary{matlab}{abs}
I do not want to have matlababs, matlababsuser, mathsabs and mathsabsuser only abs. That is too complex for a child. Any idea to simplify code?
Template example:
\documentclass[10pt,a4paper]{report}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{dictionary}
\begin{document}
This is my text book and handbook.
Today, I have learned \dictionary{matlab}{abs} and \dictionary{maths}{abs} ...
\end{document}
Best Answer
Here is a solution to your question after the update.
The idea is to store the text in an internal macro for each combination of term and dictionary and later call this macro to get the text, but of course, without having to use the internal macro itself. For this, two macros are needed,
\dictionary{<dictionary>}{<term>}
to get the text and\DefineDictionaryEntry{<dictionary>}{<trem>}{<text>}
to define the text. For example, afterthe line
will give out
The core for these macros looks like this:
In the example above the first line will define a macro
\dict@matlab@power
, which is then called with\dictionary
. Now, this is barely usable, because in case of typos it will lead to odd error messages and/or results. It would be nice to check, if the dictionary and the term exists and give out an understanable error message if necessary.In order to check, if a dictionary exists, the macro
\NewDictionary{<dictionary>}
defines an internal macro, which is later used for checking. The core for this looks like this:Here too, some checking should be done.
From the LaTeX core the command
\@ifundefined{<macro name>}{<code for macro undefined>}{<code for macro defined>}
can be used to check, if a macro does exist. And\PackageError{<package name>}{<error message>}{<help text>}
is used for error messages.Additionally, packages normaly start with
\ProvidesPackage{<package name>}[<date> <version> <short description>]
and in packages other packages are loaded with\RequirePackage{<package name>}
.All this can be put in a package
dictionary
, which is then used by the other packages (matlab
,maths
, etc.) to define the terms.Now the other packages are simple:
matlab.sty
:maths.sty
Please note that for
\ProvidesPackage
the<package name>
must be the file name without.sty
.Other packages can be written the same way:
With all this, in the document you need to load all the dictionaries you want to use: