nm

5701 Reputation

17 Badges

8 years, 304 days

MaplePrimes Activity


These are questions asked by nm

I have plain text files with comma delimited fields. Some fileds are strings and some are numeric.

When importing the file using

data:=Import(file_name,format="CSV",output=Matrix);

Maple changes any field which is string but contains a number inside it, as in "1"  to number 

And this causes all sorts of problems for me when processing the matrix data, since the program expects some fields to be strings. 

I looked at all options, but do not see how to tell Maple to keep a string as string, even if what is inside it is a number.

Here is an example file  "t.txt"

1,2,"0",4
1,2,"1",4
1,2,"A",4

I read it as follows

restart;
file_name:="C:/TMP/t.txt";
data:=Import(file_name,format="CSV",output=Matrix);

And Maple returns 

You see it changed "0" to 0 and "1" to 1.

This might be how CSV is supposed to work?. Does Maple have any option to override this default behavior in order to keep strings as strings, even though there is a number inside the string. I'll try to see if there is another format other than CSV to try which might behave better.

Maple 2021 on windows 10.

I could not find a function in StringTools package which removes all substrings (not single characters) from one long string directly. 

For example given a Latex string 

s:=" \\left \\int x \\,dx \\left";

And I want to remove all "\\left"  from it, which results in "  \\int x \\,dx "

In Mathematica, there is a function called StringDelete which removes all occurances of the substring in one call. Like this

s = " \\left \\int x \\,dx \\left";
StringDelete[s, "\\left"]

In Maple, I tried StringTools:-Remove(x->evalb(x="\\left"),s) and this did not work.Also tried

s:=" \\left \\int x \\,dx \\left";
StringTools:-Remove(x->StringTools:-Compare(x,"\\left"),s)

But this returned "leftintxdxleft"

And StringTools:-Delete needs a range, which one then has to first find.

I found this:

s:=" \\left \\int x \\,dx \\left";
idx:=[StringTools:-SearchAll("\\left",s)]; #returns index of first character in the string
StringTools:-Delete(s,idx[1]..idx[1]+4); #this only remove the first one. Need to loop to remove all.

Which returns the first substring. So one has to make a loop and keep removing all substrings found from the call to StringTools:-SearchAll

This is all too much work. But can be done.

The question is: What is the simplist way to remove all substrings from one string? All substrings are the same and the substrings can be more than one character.

Here is another example

s:="1234566X6Y67890A6BC66DEFGH";

And want to remove all "66" substrings, so the result will be

"12345X6Y67890A6BCDEFGH";

I am sure there must be an easier way to do this in Maple than having to call 2 or 3 functions and using a loop, but I could not find it so far. 

What would be the closest function in Maple to Mathematica's StringDelete? 

 

Maple generates latex for hbar as  \mathit{hbar}  instead of just \hbar which makes it not render in PDF.  Here is an example

expr:= hbar*x;
latex(expr)

The screen display is correct. But not the latex. When compiling the above in Latex this is the output

\documentclass[12pt]{article}
\usepackage{amssymb}

\begin{document}  

%Maple generated
\[
\mathit{hbar} x
\]

%default
\[
\hbar x
\]

%need amssymb for this
\[
\hslash x
\]
\end{document}

Compiling the above gives

So to use the standard hbar,  \mathit should not be used around it. 

ps. I like \hslash more myself than \hbar , so if there is a choice, will vote for \hslash for latex.

Maple 2021, windows 10. 

 

Physics:-Version()
The "Physics Updates" version in the MapleCloud is 973 and is 

   the same as the version installed in this computer, created 

   2021, May 3, 18:54 hours Pacific Time.


 

I only use latex() to convert Maple solution to Latex. I do not export whole document to Latex.

When I ask Maple to convert this solution of a PDE to latex, it generated strange Latex which is different, from the Latex it generates for same solution, when doing File->Export As->Latex.

The Latex it generated in the export case, is the one I want. The latex it generates from the latex() command, I am not able to use and is completely different. It has things like \mathit{Typesetting} and other different latex.  

Why is that? And how to make it generates the same Latex for this expression as in the export case?

First I show screen shot, then the worksheet to reproduce it

 

But Now when I save this worksheet (with only the expression I want) 

Using File->Export As->Latex, and then look at the latex for the "sol" in the latex file generated, this is what it shows (I am only showing the latex part of the above, not the whole file)

\begin{maplelatex}
\mapleinline{inert}{2d}{}
{\[\mathit{sol} \coloneqq u \left(r ,t \right)=\mathcal{L}^{-1}
\left(\frac{\mathrm{BesselJ}\left(0,10 \sqrt{-s}\, r \right) s}
{\mathrm{BesselJ}\left(0,20 \sqrt{-s}\right) \left(s^{2}+1\right)},s ,t \right)
-\mathcal{L}^{-1}\left(\frac{\mathrm{BesselJ}\left(0,10 \sqrt{-s}\, r \right)}
{\mathrm{BesselJ}\left(0,20 \sqrt{-s}\right) s},s ,t \right)
-\cos \left(t \right)+1\]}
\end{maplelatex}

The above latex I can compile standalone, and it does not have the problematic constructs found when using latex(sol)

One can see it is very different from the top one given earlier.

Why are the two latex different? Is there an extra setting one needs to adjust?  How make latex(sol) generate the same latex for the expression as found in the file generated by export as latex?

may_2.mw

update 1

Did some debugging. The problem happens when using `:-executeprintroutines`.  Tracing the latex() command in the debugger. At lines 42, it has the call

texlist := [latex:-Print(e,_rest,':-executeprintroutines',':- handleimaginaryunit',':-performonlyoncetasks',opt)];

Where above is the expression to convert to Latex. When I removed ':-executeprintroutines' the problems in latex went away. Here is an example

restart;
sol:=u(r,t) = invlaplace(BesselJ(0,10*(-s)^(1/2)*r)/BesselJ(0,20*(-s)^(1/2))*s/(s^2+1),s, t) - invlaplace(BesselJ(0,10*(-s)^(1/2)*r)/BesselJ(0,20*(-s)^(1/2))/s,s, t)- cos(t) + 1;
latex:-Print(sol)

Gives

"u ! left(r , t\right)", ` = `, `\\mathit{invlaplace} 
\\! \\left(\\frac{\\mathit{BesselJ}\\! \\left(0, 10 \\sqrt{-s}\\, r \\right) s}
{\\mathit{BesselJ}\\! \\left(0, 20 \\sqrt{-s}\\right) \\left(s^{2}+1\\right)}, s , t\\right)
-\\mathit{invlaplace} \\! \\left(\\frac{\\mathit{BesselJ}\\! 
\\left(0, 10 \\sqrt{-s}\\, r \\right)}{\\mathit{BesselJ}\\! \\left(0, 20 \\sqrt{-s}\\right) s}, s , t\\right)
-\\cos \\! \\left(t \\right)+1`

Now notice what happens when adding ':-executeprintroutines'

restart;
sol:=u(r,t) = invlaplace(BesselJ(0,10*(-s)^(1/2)*r)/BesselJ(0,20*(-s)^(1/2))*s/(s^2+1),s, t) - invlaplace(BesselJ(0,10*(-s)^(1/2)*r)/BesselJ(0,20*(-s)^(1/2))/s,s, t)- cos(t) + 1;
latex:-Print(sol,':-executeprintroutines')

it gives the problematic latex

"u ! left(r , t\right)", ` = `, `\\mathit{Typesetting}\\mcoloneq \\mathit{msup}\\! 
\\left(\\mathit{Typesetting}\\mcoloneq \\mathit{mi}\\! 
\\left(\\text{\`\`$\\mathcal\\{L\\}$"}\\right), \\mathit{Typesetting}\\mcoloneq 
\\mathit{mrow}\\! \\left(\\mathit{Typesetting}\\mcoloneq \\mathit{mo}\\! 
\\left(\\text{\`\`$-$"}\\right), \\mathit{Typesetting}\\mcoloneq \\mathit{mn}\\! 
\\left(\`\`1"\\right)\\right), \\mathit{Typesetting}\\mcoloneq \\mathit{msemantics}=\\text{\`\`atomic"}\\right)\\! \\left(\\frac{J_{0}\\! \\left(10 
\\sqrt{-s}\\, r \\right) s}{J_{0}\\! \\left(20 \\sqrt{-s}\\right) \\left(s^{2}+1\\right)}, s , t\\right)-
\\mathit{Typesetting}\\mcoloneq \\mathit{msup}\\! \\left(\\mathit{Typesetting}\\mcoloneq 
\\mathit{mi}\\! \\left(\\text{\`\`$\\mathcal\\{L\\}$"}\\right), \\mathit{Typesetting}\\mcoloneq 
\\mathit{mrow}\\! \\left(\\mathit{Typesetting}\\mcoloneq \\mathit{mo}\\! \\left(\\text{\`\`$-$"}\\right), 
\\mathit{Typesetting}\\mcoloneq \\mathit{mn}\\! \\left(\`\`1"\\right)\\right), 
\\mathit{Typesetting}\\mcoloneq \\mathit{msemantics}=
\\text{\`\`atomic"}\\right)\\! \\left(\\frac{J_{0}\\! \\left(10 \\sqrt{-s}\\, r \\right)}
{J_{0}\\! \\left(20 \\sqrt{-s}\\right) s}, s , t\\right)-\\cos \\! \\left(t \\right)+1`

I do not know what :-executeprintroutines does and how one can tell latex() not to call it at the user level. I asked about :-executeprintroutines before here

  https://www.mapleprimes.com/questions/231230-Why-Latex-Removes-Constant-From-Expression

And I could not find any documenation on it.  

I tried to define my own executeprintroutines proc() which does nothing. But it did not help

restart;
sol:=u(r,t) = invlaplace(BesselJ(0,10*(-s)^(1/2)*r)/BesselJ(0,20*(-s)^(1/2))*s/(s^2+1),s, t) - invlaplace(BesselJ(0,10*(-s)^(1/2)*r)/BesselJ(0,20*(-s)^(1/2))/s,s, t)- cos(t) + 1;
executeprintroutines:=proc()
   NULL;
end proc;
latex(sol)

The Latex was not fixed. It is same. 

May be the above will help find the issue.

 

Using latest TeXLive distribution, and current Maple 2021 maple.sty file, Maple generated Latex uses command called 

             \pdfstringdefDisableCommands

which is unknown. I found this when I was trying to compile latex generated from Student:-Calculus1:-ShowSolution command.

The above latex command is called/used in maple.sty file, but it is not defined anywhere outside. It might have been defined many years ago?  I only see one reference to it in an old posting at tex stackexchange from few years ago.

This is how to reproduce this error (one needs to have latex installed on your PC to compile the file). On windows MikTeX can be used. On Linux, TeXLive.

restart;
the_output:=Student:-Calculus1:-ShowSolution(Int(x^3,x=0..1));
latex(the_output)

Then copied the latex, and pasted it in my latex file

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage{maple}% set the path to reach this in Maple etc/ folder in its installation
\begin{document}

\[
\begin{array}{ccc}
 & {} & \textrm{Integration Steps} 
\\
 {} & {} & \int_{0}^{1}x^{3}d x  
\\
 \textrm{▫} & {} & \textrm{1. Apply the}\textrm{power}\textrm{rule to the term}\int x^{3}d x  
\\
 {} & \textrm{◦} & \textrm{Recall the definition of the}\textrm{power}\textrm{rule, for n}\textrm{≠}\textrm{-1} 
\\
 {} & {} & \int x^{n}d x =\frac{x^{n +1}}{n +1} 
\\
 {} & \textrm{◦} & \textrm{This means:} 
\\
 {} & {} & \int x^{3}d x =\frac{x^{3+1}}{3+1} 
\\
 {} & \textrm{◦} & \textrm{So,} 
\\
 {} & {} & \int x^{3}d x =\frac{x^{4}}{4} 
\\
 {} & \textrm{◦} & \textrm{Apply limits of definite integral} 
\\
 {} & {} & \frac{x^{4}}{4}{\raisebox{-0.36em}{$\Big |$}}{\mstack{}{_{x \hiderel{=}1}}}-\left(\frac{x^{4}}{4}{\raisebox{-0.36em}{$\Big |$}}{\mstack{}{_{x \hiderel{=}0}}}\right) 
\\
  & {} & \textrm{We can rewrite the integral as:} 
\\
 {} & {} & \frac{1}{4} 
\end{array}
\]

\end{document}

And now when compiling the above using the latex compiler, it gives this error

(base) >pdflatex foo5.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./foo5.tex
LaTeX2e <2020-10-01> patch level 2
L3 programming layer <2020-12-07> xparse <2020-03-03> (/usr/local/texlive/2020/texmf-dist/tex/latex/base/article.cls
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
(/usr/local/texlive/2020/texmf-dist/tex/latex/base/size10.clo)) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amstext.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsgen.sty)) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsbsy.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsopn.sty)) (/usr/local/texlive/2020/texmf-dist/tex/latex/tools/array.sty) (/mnt/g/public_html/styles/maple.sty
Package: maple 2005/03/17 v1.16
Defining Maple Utility Macros
Defining Maple Plot Environemnts
 ...Defaults to "dvips" Driver
(/usr/local/texlive/2020/texmf-dist/tex/latex/graphics/epsfig.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/graphics/graphicx.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/graphics/keyval.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/graphics/graphics.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/graphics/trig.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/graphics-cfg/graphics.cfg) (/usr/local/texlive/2020/texmf-dist/tex/latex/graphics-def/dvips.def))))
Defining Automatic Style Generation Macros
Defining Maple Spreadsheet Environments
Maple Spreadsheet and Table Support
! Undefined control sequence.
l.3248 \pdfstringdefDisableCommands
                                   {\let\(\fakemath}    % 2.
?

The above command is on line 3248 in maple.sty file

 

I tried to workaround it, but do far could not find a way.

Is there a way to fix this problem in Maple 2021 latex?

1 2 3 4 5 6 7 Last Page 1 of 115