Latex revisited

Messages in english

Modérateur : xcasadmin

Répondre
XcasEngGuy
Messages : 93
Inscription : mer. janv. 13, 2010 3:20 pm

Latex revisited

Message par XcasEngGuy » mar. nov. 16, 2021 6:34 pm

I was doing a derivation of the intersection of two circles and I ended up with a good example of the details of putting a product dot in between multiplied terms. In the attached PDF there are several long equations (that's why it's scaled so small). You should be able to zoom in and see the terms. The product dot is properly placed in most locations but, is missing in a few others. The Latex output is great for presenting work and I use it a lot. In engineering, being able to use variables with multiple characters is very useful.

We talked about this before, and I appreciate the improvements that were made.
example.zip
(28.46 Kio) Téléchargé 6 fois
Matt
Dernière modification par XcasEngGuy le mer. nov. 17, 2021 9:00 pm, modifié 1 fois.

lukamar
Messages : 312
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: Latex revisited

Message par lukamar » mer. nov. 17, 2021 8:11 pm

Hi Matt,

this behavior is intended. The conversion routine favors implicit multiplication, explicitly indicating the dot only when the result would be ambiguous otherwise. For example, when multi-character variables are involved (note that they are printed in upright font), which would end up concatenated if the dot wasn't indicated. Also, it is always put between numbers, e.g. when calling something like latex(quote(2*3)). The usual combinations such as 2x, 2xy and so on, are displayed without a dot because it is more readable.

Luka

XcasEngGuy
Messages : 93
Inscription : mer. janv. 13, 2010 3:20 pm

Re: Latex revisited

Message par XcasEngGuy » mer. nov. 17, 2021 9:22 pm

I think I understand. One more question. In the attached I noticed that a single letter followed by a number causes the number to be a subscript, a single character followed by a underscore and characters causes the characters to be a subscript. Even a single character followed by an underscore followed by a character followed by a an underscore followed by a character causes sub-subscript. However a multi-character variable name followed by an underscore and characters does not cause a subscript but simply displays the underscore.

Is it possible to make the underscore cause sub-scripting for multi-character variable names?
eq_funcs.pdf
(12.88 Kio) Téléchargé 5 fois
Thanks,
Matt

XcasEngGuy
Messages : 93
Inscription : mer. janv. 13, 2010 3:20 pm

Re: Latex revisited

Message par XcasEngGuy » sam. nov. 20, 2021 5:24 pm

For what it's worth, the following command fixes the issue (for me). Maybe it would be helpful to anyone else that wants it.

perl -pi -e 's|(\\mathrm{)([[:alnum:]]+)\\_([[:digit:]])\\*([^\\}][[:digit:]]*)*(})|\2_{\1\3\4\5}|g' <tex file from Xcas> # patch for subscripts

lukamar
Messages : 312
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: Latex revisited

Message par lukamar » lun. nov. 22, 2021 7:45 am

That's intended too, only in the latest version x_0_1 is displayed with "0_1" in subscript (there are no sub-subscripts). The default behavior is to add subscripts only to 1-character symbols (like x_index, but not xy_index). It seemed more likely to me that variables with names like "xy_index" are meant to be single symbols.
Thank you for the conversion script. I'm considering adding a command which would allow some tuning in such respects (so that different notation conventions can be selected).

XcasEngGuy
Messages : 93
Inscription : mer. janv. 13, 2010 3:20 pm

Re: Latex revisited

Message par XcasEngGuy » lun. nov. 22, 2021 6:18 pm

Interestingly, when I use the perl script, I get sub-subscripts
variables_test.pdf
(12.82 Kio) Téléchargé 7 fois
The perl script will only subscript numbers, not text.

In cygwin I use:

if [ $# -eq 0 ]
then
echo 'Convert tex file to PDF'
echo 'Usage: latex_pdf <tex file> <zoom option>'
echo 'optional <zoom option> from 10 to 10000 - 1000 is 1:1 zoom'
else
fn=$(cygpath -u $1 | sed -e 's/.[Tt][Ee][Xx]$//') # -e 's?.*/??g') # keep dir
sed -i -e 's/\\documentclass{article}/\\documentclass[landscape]{article}\n\\usepackage{fullpage}\n\\usepackage{amsmath}\n\\usepackage{geometry}\n\\geometry{letterpaper, landscape, total={247mm,170mm} }/' -e 's/,/, /g' $1
perl -pi -e 's|(\\mathrm{)([[:alnum:]]+)\\_([[:digit:]])\\*([^\\}][[:digit:]]*)*(})|\2_{\1\3\4\5}|g' $1 # patch for subscripts
latex $fn.tex
if [ $# -lt 2 ]
then
dvips $fn.dvi # -t letter -t landscape -Ppdf $fn.dvi
else
dvips -x $2 $fn.dvi # -t letter -t landscape -Ppdf -x $2 $fn.dvi
fi
ps2pdf $fn.ps $fn.pdf
rm $fn.aux
rm $fn.dvi
# rm $fn.log
# rm $fn.ps
cygstart $fn.pdf
fi

lukamar
Messages : 312
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: Latex revisited

Message par lukamar » mar. nov. 23, 2021 9:03 pm

Maybe the patch creates sub-subscripts recursively? Since you moved mathrm from \mathrm{var_index1_index2} to the first index, obtaining var_\mathrm{index1_index2}, the patch does its work again on the new subscript.
I will change the default behavior for indices for numeric subscripts, so that they are always printed no matter how many characters precedes the underscore (so that xy_1 would be printed with 1 in subscript). That seems reasonable and would perhaps solve your problem.

XcasEngGuy
Messages : 93
Inscription : mer. janv. 13, 2010 3:20 pm

Re: Latex revisited

Message par XcasEngGuy » mar. nov. 23, 2021 10:28 pm

That sounds good.

Actually, the var_\mathrm{index1_index2} is send directly to the Latex->PDF in cygwin, so I think the sub-subscript stuff is handled by the Latex to PS to PDF routine.

The perl one-liner does this:

x_{1}+x_{1}+\mathrm{xy1}+\mathrm{xy\_1}+\mathrm{x0\_1}+\mathrm{xy\_1}+\mathrm{xy\_0\_1}+x_{\mathrm{0_1}}=\gamma_{1}+y_{12}+z_{\mathrm{fun}}

to

x_{1}+x_{1}+\mathrm{xy1}+xy_{\mathrm{1}}+x0_{\mathrm{1}}+xy_{\mathrm{1}}+xy_{\mathrm{0_1}}+x_{\mathrm{0_1}}=\gamma_{1}+y_{12}+z_{\mathrm{fun}}

tex files.zip
(890 octets) Téléchargé 4 fois
by the way, the full script I posted also changes the packages, etc. at the beginning of the tex file, the perl script only changes the equation stuff. So the beginning of the two files in the zip file are different.
comparison.pdf
(300.82 Kio) Téléchargé 6 fois
Matt

lukamar
Messages : 312
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: Latex revisited

Message par lukamar » mer. nov. 24, 2021 10:33 am

Yes, here it is: the latex code \mathrm{xy\_0\_1} gets converted to x_{\mathrm{0_1}}, which causes the sub-subscript "1" because the inner underscore is not prefixed by \. Shouldn't the result rather read as x_{\mathrm{0\_1}}?

XcasEngGuy
Messages : 93
Inscription : mer. janv. 13, 2010 3:20 pm

Re: Latex revisited

Message par XcasEngGuy » sam. nov. 27, 2021 3:34 am

Actually, I was trying to get a sub-subscript. I forgot I caused the script to trim the \.

However, you are right.

Matt

Répondre