# The Higher Education and Research forge

 Home My Page Projects Code Snippets Project Openings Développement de WIMS
 Summary Activity Forums Tracker Tasks Docs Surveys News SCM Files Listes Sympa

# [#6910] interprétation de variable dans un document

Date:
2010-06-07 21:08
Priority:
3
State:
Open
Submitted by:
Eric Reyssat (reyssat)
Assigned to:
Nobody (None)
Hardware:
none
Operating System:
none
Version:
none
Severity:
none
Resolution:
none
URL:
état:
Open
Summary:
interprétation de variable dans un document

Detailed description
Sous versions 3.64 et 4.00, si un document contient

\def{text x=5}
\(exp) \(xyz) \(xyv)

il renvoie

exp 5 y z xyv

Pourquoi le x est-il interprété une fois et pas les autres ?

Ca n'arrive pas dans un exercice.

Eric
Message
Date: 2010-12-17 09:09
Sender: Eric Reyssat

Pour memo, voir aussi le message "tex dans un document" de Chantal Causse sur le forum wimsedu (16/12/2010) concernant la différence entre docs et exos dans le traitement des formules.

Date: 2010-11-15 17:39
Sender: Eric Reyssat

This being a bug or a feature might be discussed (see end of comment).

But it certainly is the drawback of rawmath being "too" clever when trying to recognize usual constants and variables in badly written expressions. And the difference between documents and exercise is that the pretreatment of texts is different.

The cleverness of rawmath is used to allow users to write expressions like exp(2ipix) without blank between variables and constants 2//i//pi//x. But of course exp(foobar) should not be split like fo//ob//a//r or so.

Here are some technical factual details :
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

We want to output the string "xy" as mathematical expression after we give the value 5 to x.

The function insmath with argument xy calls rawmath with argument xy. This one looks in a table of usual functions and variables to see if the expression is constructed out of them. The one-letter entries of this table are e,i,x,y,z (two constant, three variables), no other. So it splits our expression xy into x*y. Then insmath call htmlmath on this expression, which gets rid of the * character and looks for a value of the variables x and y. Since a value for x is found, it outputs 5y.

If we replace the string xy by xv, rawmath doesn't split it because v is not in the "usual variable name" table. So insmath calls htmlmath on the same expression xv, and since this has no assigned value, the output is xv.

In the same vein, you can try to display in math mode the expression exp(2ipix)=exp(2ipiv) after giving values to x and v.

The difference between document and oef comes from pretreatment :

In the case of a document, assigning a value to x is translated into a line "!set m_x=5", and then calling for the math expression xy is translated into "!insmath xy"

In the case of oef, the math expression is also translated into "!insmath xy" but the first assignment is translated into "val7=5" (if x is 7th variable to be assigned). So the variable x doesn't exist any more, only val7 has a value. If we want to display x*y (or x y with a blank between them) then this is translated to val7*y : val7 has a value so the output is now 5y as in the document.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

These facts have now to be discussed :
compare the pros and cons of the cleverness of rawmath, of the different pretreatment in documents and oefs, discuss what usual variable names should be in the table (if any), ....

Any idea is welcome.

Eric

Date: 2010-11-14 12:51
Sender: Eric Reyssat

C'est dû à rawmath.c, je regarde.
Eric