This manual shows how to make use of the facility Maple has to export worksheets to latex and html in creating papers, manuals, classnotes, etc.
Maple worksheets have been exportable to latex since there such things, and we, along with many other researchers have used Maple to produce eps diagrams and tex source files for papers. We have used Perl scripts to massage the tex output from Maple to produce classnotes, manuals, and textbooks. For example, the pdf and ps files in the following places were produced by this method.
http://www.ms.uky.edu/~carl/hand99/hand98.pdf Maple handbook for calculus students
http://www.ms.uky.edu/~carl/chisel/linprog/all/linprog.ps Ma 416 class notes
http://www.msc.uky.edu/carl/ma123/kob98/kob98tex/kob98.ps Calculus book by Koblitz
http://www.ms.uky.edu/~carl/chisel/vpsf97/all/book.ps Visual Problem Solving by Eakin and Eberhart
http://www.ms.uky.edu/~carl/ma341/lattice5.pdf A research paper in Topology
Recently, we have been more concerned with the export of Maple worksheets to html, because these can be used to prepare homeworks for Web Homework System (WHS), a Math Sciences service for teachers hosted on http://www.mathclass.org
However, for various reasons, we have even more recently become interested in developing a method for massaging the latex export from Maple which does not rely on Perl scripts. The package latextools , whose current state is described here, implements the method. See the words latexit and rootwork described below; also see the words htmlit and htmlrootwork below for processing html export in a similar fashion. See also the words mwsit and mwsrootwork for processing the source worksheet in a similar fashion.
Latextools is still in development. Suggestions and comments should be sent to carl@ms.uky.edu
How to Latex the raw Latex export from Maple 9
We assume you are working on a Windows 2000 or XP machine which has access to Maple 9.01 or 9.5, MiKteX 2.4 and Gsview4.5. Most of the Math Sciences machines at UK are in this category.
You can equip your home machine with these tools with little effort.
The latest version of MiKteX is available free at http://www.miktex.org/
and the latest Gsview4.5 is free at http://www.cs.wisc.edu/~ghost/.
Gsview requires a Ghostscript.
You can use gs811 (also free) from http://www.cs.wisc.edu/~ghost/doc/AFPL/get811.htm
You can install these on your computer by following the instructions supplied.
Maple 9.01 or 9.5 is free to any employee of the University (Math Sciences has a site license). For others, the student version of Maple 9.5 is around $120 and should work fine, although I haven't tested it.
Maple2e style files. You must have the latex style files that Maple uses. These can be found in the ETC directory in the Maple directory. There are 7 files in the directory. Select them and make a copy.
Now, create a directory that you will keep your Maple source worksheets and all the tex export from them. We will assume the directory is c://mystuff. Paste the 7 style files (8 files for 9.5) into the directory . If you have MikTex on your machine, you can put these files in the texmf folder and refresh the style files from the start button by selecting
MikTex->MikTex Options->General->Refresh Now
One other thing, very important. Use the Classic Worksheet interface in Maple 9. In Windows, you can change the Maple worksheet file association using the Worksheet File Association Selector application from the Tools folder of the Maple 9 Start menu. The standard Worksheet interface is significantly different and will not work reliably.
You are ready to latex files with the latextools method. It would be nice to have a Latex 2e manual handy, if you want to put in much raw latex into the worksheet. I use a manual by Kopka and Baly \cite{kopka} The MiKteX installation has good online help. Also there are plenty of other nice links. Here is one
http://it.metr.ou.edu/latex/latex2e.html
The procedure if you are doing it by hand
Using the Classic Worksheet Interface , open up a Maple worksheet and type in some stuff: text, input, and output.
Save the worksheet to the directory with the name, say sample. Save it as a classic (.mws) worksheet.
Export the worksheet to Latex. This is done from the file menu. Accept the file name suggested (sample.tex) and the suggested location (c://mystuff)
Open a cmd prompt. You can do this from the Start Button. Choose Run and type cmd in the input line and press enter.
In the window that opens up, you have to change directory. Type c: and press enter. Type cd mystuff and enter. The prompt line should read c:/mystuff
Now do a dir. That is, type dir and press enter. You will see a listing of the files in the directory. One of them will be sample.mws. That is the souce worksheet. Another will be sample.tex. That is the tex export from maple.
Now type latex sample and press enter. You will see some processing, ending with the message "Output written on sample.dvi".
Now type dvips sample and press enter. You will see some processing. At the end a postscript file sample.ps will have been created.
Now open up Gsview45 and look at the file. If you want to make changes, go back to the source worksheet, make the changes and resave and reexport. Then go to the command window and latex and dvips the file again. Look at the file again with Gsview. Repeat as necessary.
That's it.
The procedure outlined above has defects. Any changes in the documentstyle or preamble must be made by hand in the tex file that is exported from Maple. When you do this, the source document is not the Maple worksheet anymore, because if we reexport the worksheet to latex, the old tex file is written over, and any changes made by hand are lost. The package latextools is written to allow you to keep the worksheet as the source document.
Latextools is a package of Maple words written to process Maple worksheets which have been exported to latex. You will need a worksheet which has the package in it. It will be in a section at the top of the worksheet. This will be your management worksheet, where you will keep the commands you are using to process your worksheets. Save the management worksheet in the work directory c://mystuff. We will assume you call it manage.mws. At the beginning of a Maple session where you plan to use latextools, open the management worksheet containing the package latextools. It will be in a section which you should open and execute, then close. Check to make sure that Maple is running in the shared kernel mode . Then the assignments you make in one worksheet are valid in any worksheet open in the same Maple session. So the words in latextools can be used with any worksheet in the session. Keep this worksheet open, because you will come back to it.
The package latextools contains a word latextoolshelp() which gives a brief help message
> | latextoolshelp(); |
latextools version 5/1/2004: A package to process maple export to latex and/or html.
To process a single worksheet, you can use latexit. See latexit(Help=yes) for help.
To combine several worksheets with a rootfile, use rootwork. See rootwork(Help=yes) for help.
To process a WHS homework prepared with MCtools[tagit] (Nov 10 2003 or later), regenerate the
tagit homework with LATEX_:=yes, then export to latex, then process it with latexit using the
option WHSprobs=yes.
The package also contains words to process the html export from Maple.
Export to html, then use
htmlit("worksheet","path") to process. See htmlit(Help=yes) for help.
To create an html root, use
htmlrootwork("rootname","path",Files=["file1","file2",...]); See htmlrootwork(Help=yes) for help.
The package also contains three words, mwsit, unmwsit and mwsrootwork, which
manage the bookmarks of a group of one or more worksheets.
See mwsit(Help=yes) and mwsrootwork(Help=yes) for help.
> |
The two main words in the package are latexit and rootwork .
Using latexit to process single worksheets.
If your worksheet does not have any raw latex in it, and consists only of Maple commands, output and text, you can simply export the worksheet to latex (say it is sample.tex in c:/tmp, then execute the command latexit("sample","c:/tmp"). A file samplewhs.ps will be generated in c:/tmp which you can view and print with ghostview. Otherwise, you can follow the procedure below.
1. Prepare your document in a worksheet.
2. To omit a block of lines from the final document, put a *OMIT on the line above and a *TIMO on the line underneath (the * should be replaced by an underscore,). We call this a *OMIT *TIMO block . Thus, for example, you can put scratch work, notes, computations, etc that you needed to make your document between an OMIT and TIMO and exclude it from the tex file.
3. You can use Maple to generate diagrams and typeset mathematics for your document. These are handled automatically.
4. You can also use ordinary latex to typeset math that Maple cannot handle. There are two ways to do this.
i) If there is a block of lines of latex, put a *LATEX on the line above and a *XETAL on the line underneath (the * should be replaced by an underscore). We call this a *LATEX *XETAL block .
ii) Any latex which is outside a block of lines should be selected and converted to the latex character style , which should be modified as to be visible. For example the polynomial $y=u^2 - 5u + 2$, when converted to latex character style typesets to $y=u^2 - 5u + 2$ .
5. Save the worksheet to your work directory c:/mystuff. We will assume the name you give it is mysheet.mws. Then export the worksheet to latex in this directory.
6. In the management worksheet, type the input below and press enter.
> | latexit("mysheet","c://mystuff"); |
> |
The first argument is the name of the worksheet you are processing. The second argument is the location of the tex file mysheet.tex
What happens is that the file mysheet.tex is opened and written to a new file mysheetwhs.tex (in c://mystuff) after some changes are made. Also any eps graphics files mysheet*.eps are recolorized and the default border is removed. Then the file mysheetwhs.tex is latexed to produce a dvi file mysheetwhs.dvi. Then the file mysheetwhs.dvi is dvips'ed to produce a file mysheet.ps
At that point you can open Gsview4.5 and view the postcript file mysheetwhs.ps. If it satisfactory, you can convert it to a pdf file using the convert menu in Gsview4.5. Otherwise, you can make needed changes to the source worksheet mysheet.mws and go through the process again until perfection is obtained.
That's it.
Here is a piece of a test from 1988 made up in latex. I have just pasted it into a textcell. There was a picture missing, so I generated the picture with Maple. I also added a problem which I created in place with Maple. The code has been block off with OMIT and TIMO. The test has been enclosed with the pair LATEX and XETAL. Note. In order that latexit work correctly, it helps to put the tags OMIT, TIMO, LATEX, and XETAL just after the beginning of a group range. These can be created in a text cell by putting the cursor where you want to break off a section and pressing the F3 key. Join groups with the F4 key. (See the Edit Menu).
First with *'s replacing the underscore's to disable the tags.
*OMIT
> | f := unapply(piecewise( x<-1,1,x<5,-1,1 ),x); |
> | pl1:=plot({int(f(x),x)},x=-2..6,discont=true,thickness=3): |
> | pl2:=plot(int((x+1)*(x-5),x),x=-2..6,thickness=3): |
> | plots[display](matrix([[pl1,pl2]])); |
> |
*TIMO
*LATEX
\begin{enumerate}
\item
If $y=u^2 - 5u + 2$, and $u=8 + 1/x$, then the derivative $\Frac{dy}{dx}$
at $x=2$ is
\vspace{.5in}
\item
If $f(x)=\sqrt{3x^4 - 11}$, then $f'(x)=$
\vspace{.5in}
\item
Suppose a function $y=f(x)$ has both of the following properties:
(1) $f'(x) > 0$ when $x > 5$ and when $x < -1$, (2) $f'(x) < 0$
when $-1 < x < 5$. Which of the graphs could
be the graph of the function?
\end{enumerate}
*XETAL
Next with the tags activated.
_LATEX
\begin{enumerate}
\item
If $y=u^2 - 5u + 2$, and $u=8 + 1/x$, then the derivative $\Frac{dy}{dx}$
at $x=2$ is
\vspace{.5in}
\item
If $f(x)=\sqrt{3x^4 - 11}$, then $f'(x)=$
\vspace{.5in}
\item
Suppose a function $y=f(x)$ has both of the following properties:
(1) $f'(x) > 0$ when $x > 5$ and when $x < -1$, (2) $f'(x) < 0$
when $-1 < x < 5$. Which of the graphs could
be the graph of the function?
\end{enumerate}
_XETAL
> |
> |
The Help=yes option of latexit
If you execute latexit with the option Help=yes set, you get this help message
> | latexit(Help=yes); |
5/1/2004
Export your worksheet to latex. Then
latexit("worksheet","path")
where
worksheet is the name of the worksheet (omit the .tex suffix)
path is the path to the directory with the exported tex files, eg, c://temp
Options:
NumPass=2 is the number of passes through latex
FixEps=yes: set to no to keep the pictures grayscale
Color: set to no to keep the fontcolor black
Docstyle=DOCSTYLE,
Pkgs=PKGS,ExtraPkgs="",
Preamble=PREAMBLE,ExtraPreamble="",
Abbrevs=ABBREVS,ExtraAbbrevs=[],
Styles=PSTYLE,ExtraStyles=""
Dvips=no: set to no if you want to generate postscript by hand
Help=no: set to yes to get this message
WHSprobs=no: set to yes if you want to process a WHS homework which has latex versions of
the problems (use MCtools Nov 15 2003 or higher with LATEX_ set to yes or both before you
re-tagit and export to latex)
Picwidth=2.5: set to larger or smaller width in inches to change the default size of diagram
(Note: Import external eps, png, bmp, jpg files with
_pic[name.xxx;bb=llx lly urx ury,height=yin,width=xin] in Latex Char style)
Purpose="notes": set to amspaper to use ams styles.
> |
As you can see, latexit has a lot of options, all with pre-assigned defaults. Initially, you would accept all the defaults, but you may want or need to change an option. Most of them are sufficiently explained in the help message.
There is a large group of options, starting with Docstyle and ending with ExtraStyles, that allow you to change the preamble of the latex export from Maple. For example, Docstyle is set to "[11pt]{article}". If you wanted 12pt, you could change that easily.
For wholesale changes in these options, you will want to examine what the current defaults are. I have put their definitions in the appendix, in the section on Default Styles. There is one wholesale change you can make: if you want to use the ams styles, change the Purpose= option to amspaper .
The WHSprobs= option is important if you plan to use latextools to extract latex versions of the WHS homework problems. It is covered in some detail later in this manual.
Latexit is still in a state of developement, so your suggestions are solicited.
Take the source worksheet for this manual, and save to your work directory c://mystuff as say latextools.mws. Then export it to latex and process it with latexit.
Importing Graphics.
When a pictured generated by a Maple command is exported to latex it is exported as a grayscale eps file, and the style files that come with Maple handle the inclusion of the picture into the tex file automatically. The option Picwidth= can be set to change the default size of the graphic. One of the functions of latexit is to restore the color in the eps file and remove the border around the picture. This works for all the standard colors, and if you really have a color you want duplicated, you can addit to the list of colors to be restored.
Occasionally, you may want to insert a graphic into the worksheet that was not generated with Maple. Say, for example, you have a jpg , bill.jpg, you want in your document. Put it in the export directory, and insert this line in your worksheet
(underscore)pic[bill.jpg;bb=0 0 640 480,width=640pt,height=480pt]
Now, when you export and latexit, the diagram will occur in the postscript output. You may have to experiment with the bb ( bounding box ) entry to get things to look right.
> |
The Purpose=amspaper option
If your texmf installation includes amstex, you can write math papers using these styles. A sample can be found at http://www.msc.uky.edu/carl/communicating_math/Examples_page.htm
We have added some abbreviations. For example for _df we substitute f^{\prime}. So, wherever a _df is found, it is replace with f^{\prime}.
We have also added some newcommands to the preamble.
You can see how these changes are fed into latexit.
Basic instructions for use.
1 Open the latextools section and execute it.
2. Execute these input cells below. They define the abbreviations and newcommands needed to process this particular set of notes.
> | abrv:=[["\\_df","f^{\\prime}"], ["\\_Kn","$K_{2}$"], ["\\&","&"],["\\_S2","$S_{2}$"]]: preamb := "\n\\raggedright \\newcommand{\\shseq}[4] {\\left(#1_{#2}\\right)_{#3}^{#4}} \\newcommand{\\pt}[2] {\\left(#1_{i}\\right)_{#2}^{\\infty}} \\newcommand{\\pttwo}[2] {\\left(#1\\right)_{#2}^{\\infty}} \\newcommand{\\map}[3] {#1_{#2}:#3_{#2+1} \\to #3_{#2}} \\newcommand{\\invlim}[2] {\\varprojlim\\left(#1_{i},#2_{i}\\right)} \\newcommand{\\shinvlim}[2] {\\varprojlim\\left(#1,#2\\right)} ": |
> |
3. Save the worksheet in a directory and export it to latex in that directory.
4. Then execute the latexit command below, after modifying the first argument to the name of the worksheet as you saved it, and the second argument to the path to the directory containing the latex export.
> | latexit("buckets04", # change buckets04 to whatever name you save the worksheet with "c:/carl/whit3", # change this to the folder where you exported to latex Purpose=amspaper, ExtraAbbrevs=abrv,ExtraPkgs={"amscd"}, ExtraPreamble=preamb,FontSize="12pt"); |
index words duplicated
buckets04whs.tex created
buckets04whs.dvi created.
fixed eps files (removed their borders and recolored if Color=yes is set)
buckets04whs.ps created sucessfully.
finished
5. If you are performing step 4 on a math sciences machine, everything should go fine. Then you can open the postscript file (it is named the same as your worksheet with 'whs' appended) with ghostview and view it. If it is what you want, save it to pdf file for dissemination.
> |
Using rootwork to process a rootfile of worksheets
You may want to gather some of your worksheets into a set of class notes, or a manual, or a book.
You may want a table of contents, perhaps an index. You may want a titlepage. You can make a rootfile to handle this, using the word rootwork in latextools. Rootfiles in latex are a very convenient way of developing a set of classnotes, or homeworks, or writing a book from a lot of separate texfiles. A latex rootfile is a short file which only has a preamble and \begin and \end{document} lines. Between these are a bunch of \include{filename} statements, where filename is a latex file with no preamble, nor a begin and end document line. Then when you latex the rootfile it processes all of the included files. In this way you can 'grow' a book or set of class notes, complete with table of contents and an index if you want.
1. open your management worksheet and execute latextools
2. select the files that you have processed with latexit that you want to put in your rootfile. For example, say you want to make a manual out of your file mysheetwhs.tex that you created above.
3. type the following input line and execute.
> | rootwork("myroot","c://mystuff",Files=["latextoolswhs"]); |
> |
What happens is that a short file myroot.tex is created which has a preamble, and an include for the file latextoolswhs. Then this file is latexed twice and then dvips'ed to create a file root.ps which has a table of contents and an index. You can examine the file root.ps with Gsview4.5. You can expect to want to make changes. This could be done by editing the root file directory, however we would like to do it by making changes in the management worksheet.
To change the table of contents. You do this in the source worksheets by changing the way the manual is sectioned. See the Insert Menu for creating and deleting sections and subsections. See the Edit Menu for splitting and joining sections. You can also copy closed sections and then paste them to other locations in the same or different worksheets. Then rexecute the rootwork command.
To add or delete words from the index. Add a word by selecting it with your cursor and changing the character style (upper left hand corner of worksheet) to index. In this worksheet, that color of the text changes to darkgreen to make the index words visible.
To add a title, use the Title= option .
> | rootwork("myroot","c://mystuff",Files=["latextoolswhs"],Title="A manual for latextools"); |
> |
The Help=yes option. Use this to print out a help message for rootwork
> | rootwork(Help=yes); |
11/27/2003 rootwork("rootname","path",Options)
where rootname is the name you want for the rootfile
and path is the path to the directory with the latex files.
Brief instructions:
Export your worksheets to latex and process them with latexit.
Make a rootfile with rootwork, and add the files as includes to make a large document.
Options:
Newroot=yes set to no if you don't want to redo the rootfile.
Files=[] set to a nonempty list of files you want to include in the rootfile.
Numpass=2
Title="" set to a non empty string if you want a title page.
Author"" set to the name of the author for the title page.
Frontpiece="" set to the name of a graphic file (eps or jpg).
Dvips =yes gives a postscript file
Fonts=regular set to sansserif for MS sans serif
Lengths=" set to pageheight, pagewidth, etc
Amspaper=no set to yes if the documentstyle is amsart
Mkindex=yes creates an idx file of words in Files marked with Character style index
Contents=yes gives a table of contents
Pagestyle=headings set to none if you don't want that.
> |
As you can see, rootwork has as many options as latexit. The help message explains most of them sufficiently well.
The word rootwork is under developement, so your suggestions are solicited.
Processing WHS homework with latextools
MCtools is a Maple package which is used to produce homework sets that students can access from the WHS server at
There are a large number of homework sets here, and we want to describe a way of converting these to a latex format.
In order to do this successfully, you will need to know a little about how to use the MCtools package. Read the Manual for WHS Authors, and the rest of this manual.
The procedure for adding latex to a WHS homework
First, you must open the source worksheet that was used to create the WHS.
Next, replace the MCtools section at the top with an MCtools dated Nov 15 or later. Execute it, and enclose the top of the worksheet in an *OMIT *TIMO block Also, in the top of the worksheet, place an input cell with the assignment LATEX_ := yes. Execute this.
Then you must convert each tagit line in the worksheet to the 'freeform' style and rexecute. With LATEX_ set to yes, you will only get latex output. With LATEX_ set to both, you get latex and WHS versions of the problem.
Periodically, export your worksheet to latex and execute latexit(worksheet,path,WHSprobs=only). This will produce a file worksheet_lawhs.ps which you can inspect with GSview4.5. A couple of examples are shown in the next section.
Most often, the problems in a WHS worksheet will be parameterized and a problem generator will have been constructed so that different versions of the problem (with different values for the paramters) can easily be generated. Then when we get ready to generate some problems, we set the global variable LATEX_ to yes (or both if we want to install the homework on WHS also).
> | LATEX_:=yes; |
Now the procedure f defined below is the problem generator. Below that we have a call to f.
> | f := proc(di,qu,re,x) local pr,pr1,pr2,pr3,q,r; pr := collect(expand(di*qu+re),x); pr1 := collect(qu+x,x); pr2:= collect(qu-2*x^2,x); tagit("We know by the remainder theorem that ",pr = q(x)*di + r(x),["for some polynomials ",q(x)," (the quotient) and ",r(x)," (the remainder), where ",r(x)=0," or the degree of ",r(x)," is less than the degree of ",di,". Find the quotient and remainder."],["The quotient , ",q(x)," = "], _ALlabels([qu,pr1,pr2,"none of the others"]), ["The remainder, ",r(x)," = "] ,_ALlabels([re,re+x,re-2,"none of the others"])) end: |
> |
> | f(x-3,x^2+x-1,4,x); |
_LATEX
\item \
We know by the remainder theorem that
${x}^{3}-2\,{x}^{2}-4\,x+7=q \left( x \right) \left( x-3 \right) +r \left( x \right) $
for some polynomials q(x) (the quotient) and r(x) (the remainder), where r(x) = 0 or the degree of r(x) is less than the degree of x-3. Find the quotient and remainder.
The quotient , q(x) =
Circle correct answer:\\
\begin{tabular}{llll}
${x}^{2}+2\,x-1$ & $-{x}^{2}+x-1$ &none of the others& ${x}^{2}+x-1$ \\
\end{tabular}\\
The remainder, r(x) =
Circle correct answer:\\
\begin{tabular}{llll}
$4+x$ &none of the others& $2$ & $4$ \\
\end{tabular}\\
\vspace{12pt}
_XETAL
_KEY
\begin{tabular}{llll}
$\diamond$& ${x}^{2}+x-1$ &$\diamond$& $4$ \\
\end{tabular}
_YEK
tangent problem: Putting diagrams in.
This problem has a parameterized diagram which is inserted into the problem. You can define the diagram right in the problem generator, or do it the way we have: build the digram generator first and call it from the problem generator.
> | solve(a^2=x*(x+b),x); |
> |
> | diag := (P,A,B,C,clrs)->plots[display]([plottools[disk]([0,0],4,color=clrs[1]), plot([[0,4],[6,4],[4*cos(-Pi/3),4*sin(-Pi/3)]],thickness=2,color=clrs[2]), PT([0,4.5],A),PT([6,4.5],P),PT([4*cos(-Pi/3)+.5,4*sin(-Pi/3)-.5],C),PT([4.5,0],B)],axes=none,scaling=constrained): |
> |
> | tanprob:=(P,A,B,C,PC,PA,BC,PB,a,b,clrs,err)-> tagit(["A theorem from plane geometry tells us that if from a point ",P," outside a circle a tangent ",PA," and a secant ",PC," is drawn, then "],[PA]^2=PB*PC,[", where ",B," is the point in the interior of ",PC," which is on the circle: see the diagram below (not drawn to scale). Find ",PC," when ",PA = a," and ",BC = b,". Give the answer to within ",err],diag(P,A,B,C,clrs),precision=err,_AC(evalf(1/2*b+1/2*sqrt(b^2+4*a^2)))): |
> | LATEX_:=yes; |
> | tanprob(P,A,B,C,PC,PA,BC,PB,10,12,[tan,blue],`.01`); |
_LATEX
\item \
A theorem from plane geometry tells us that if from a point P outside a circle a tangent PA and a secant PC is drawn, then
${[{\it PA}]}^{2}={\it PB}\, \left( {\it PC} \right) $
, where B is the point in the interior of PC which is on the circle: see the diagram below (not drawn to scale). Find PC when PA = 10 and BC = 12. Give the answer to within .01
$\!$
\rule{1in}{.1mm}
\vspace{12pt}
_XETAL
_KEY
\begin{tabular}{ll}
$\diamond$& $ 17.66190379$ \\
\end{tabular}
_YEK
The idea would be to convert an entire homework with say 5 versions of each problem to latex. We can use latexit with the WHSprobs=only option to monitor the look of the problems. But we would use extractlatex to generate a homework version in a manner mirroring WHS versions.
Generating homeworks with extractlatex.
Suppose you have processed all of the problems in a WHS homework with latexit. Then you can extract a selection of problems, by setting the appropriate options. These are listed in the help message from extractlatex
> | extractlatex(Help=yes); |
version 5/1/2004 extractlatex("worksheet","path") where worksheet is the name of a WHS worksheet
you have exported to tex and path is the location of the directory which contains the export.
It creates a file worksheet_la.tex in the same directory which contains all the extracted problems. Process this with latexit.
First execute the worksheet (problem by problem) with LATEX_ set to yes (for latex only) and both (for both latex and html versions of the problems).
Then export the worksheet to latex. Then execute extractlatex.
Options:
Probs=[seq(i,i=1..400)] set to the list of problems to be extracted.
Number=400 set to the maximum number of problems in a homework.
Multiplicity=1 set to the multiplicity of the homework.
Version="-1" set to any string to get a version.
Randomize=no set to yes to change the ordering of the extracted problems or to a specific permutation
PPP="" set to 3 to get 3 evenly spaced problems on a page or to a list of the problem numbers you want newpages after or to a list of latex spacing strings.
Head="" set to a homework Title string if wanted.
Name="" set to the name you want for the extracted tex file.
Key=no set to yes if you want a key (and have provided one)
> |
Two examples of homeworks which have been prepared in the manner described above can be found in source at
https://www.msc.uky.edu/carl/communicating_math/Examples_page.htm
triangles.mws is a standards based geometry homework prepared by Lee Roher, a teacher at West Jessamine High School.
polynomials.mws is a more modest homework on polynomial arithmetic used in Ma 109 College Algebra.
Exercise: Get the source for one or both of these homeworks and extract a 5 question quiz from it.
> |
Generating versioned exams from WHS homework: an example
To create an exam from a collection of WHS problems.
1. open latextools and execute, then close; open MCtools and execute, then close; set LATEX_ to yes or both, and rexecute the problems. You will get latex versions of the problems.
2. export the worksheet to latex in a directory.
3. modify the cover sheet bill defined in makewhstest to fit your exam
4. modify the calls to extractlatex and latexit in makewhstest to suit your needs.
5. Bring up ghostview and examine the postscript file. When you like it, convert to pdf using pdfwrite in ghostview or better yet adobe distiller.
> |
An example exam can be found at
https://www.msc.uky.edu/carl/communicating_math/Examples_page.htm
The exam here has 10 questions each with five instances.
Here we are defining three versions of the exam: the first item is the version number, the third item is the list of absolute numbers in ascending order of the problems used in the exam, and second item is the list of the order in which the problems occur. Thus in the first version 100, problem 21 occurs 3rd in the exam.
> | versions := [[[100], [1,2,5,4,3,6,7,8,9,10], [1, 6, 11, 16, 21, 26, 31, 36, 42,46], "test3"], [[110], [10,9,8,7,6,5,4,3,2,1], [2, 7, 12, 17, 22, 27, 32, 37, 43,47], "test3"], [[120], [3,1,5,7,9,2,4,6,10,8], [3, 8, 13, 18, 23, 28, 33, 38, 44,48], "test3"]]; |
> |
The current state of makewhstest
file is the name of the worksheet (without suffix)
path is the path to the folder containing the exported latex
ver is the version we want. we will call it below with ver set to versions[1].
> | makewhstest := proc(file,path,ver,spcing) local defaults,opts,help,head,bill,j,v,getperm,abrv; defaults:=Help=no,Head = file; opts:= subs([ op(select(type,[args],`=`)),defaults], [Help,Head]); help:=opts[1]: head:="Test 3 version ": #needed to get the index permutation for the problems getperm := proc(l) local p,i,j; p:= NULL: for i from 1 to nops(l) do for j from 1 to nops(l) do if l[j]=i then p := p,j; fi; od od; [p] end: #modify this to suit your task. Use cover(Help=yes); for additional help bill:=cover(Title="Test 3\\\\Ma 310 002\\\\Problem Solving for Teachers", Date=cat("May 6 2004, ",cat("version ",convert(ver[1][1],symbol))), Instructions=cat("There are ",nops(ver[2])," questions on this exam, each worth 11 points. Please work each problem in the space alloted. In case you need extra room, please use the back of the preceeding page. You may use a calculator, but you must show your work in such a way that it is clear how you obtain your answer. Unsupported answers will receive little or no credit. You may ask about the statement of a problem, but please do not ask me about your answer."), Posspts=[seq(11,i=1..nops(ver[2]))], Bottom="\\noindent\\textbf{Name: }\\rule{2in}{.01in}"): abrv:=[["{\\tt `f '`}","$f^{\\prime}$"], ["{\\tt `g '`}","$g^{\\prime}$"], ["{\\tt `k '`}","$k^{\\prime}$"], ["{\\tt `p '`}","$p^{\\prime}$"], ["{\\tt `f(x)`}","$f(x)$"], ["{\\tt `f '(x)`}","$f^{\\prime}(x)$"], ["{\\tt `h '`}","$h^{\\prime}$"], ["\\frac ","\\Frac "], ["\\lim _","\\Lim _"], ["\\int _","\\Int _"], ["\\int \\!","\\Int "]]; #modify this to suit your need. Use extractlatex(Help=yes) for additional help extractlatex(file,path, Number=16, Key=yes, Head=bill, PPP=spcing,Probs=ver[3], Randomize=getperm(ver[2]), Name=cat("ver",convert(ver[1][1],symbol))); v := cat(head,convert(ver[1][1],symbol)); #modify this to suit your need. latexit has Help also. latexit(cat("ver",convert(ver[1][1],symbol),"_la"),path, GenAbbrevs=abrv, ExtraPreamble=cat("\\raggedright\n\\topmargin=0.5in\n\\textheight=8.75in \\pagestyle{myheadings}\n\\markright{",v,"}"), Dvips=" -r* ", Docstyle="[titlepage]{article}") end: |
Now here is a call to the test generator to make a hardcopy version of the WHS version. If you want more versions, you have to repeat the process of retrieving the WHS version, saving it to a txt file somewhere, then running getnums on it.
> |
> | makewhstest("test3","c:/carl/test3",versions[1], ["\\newpage","\\vspace{2.5in}", "\\newpage","\\vspace{2.5in}", "\\newpage","\\vspace{.5in}", "\\newpage","\\vspace{.5in}", "\\newpage",""]); |
The test3 eps files are already recolorized.
ver100_la.tex created: 10 problems
index words duplicated
ver100_lawhs.tex created
ver100_lawhs.dvi created.
fixed eps files (removed their borders and recolored if Color=yes is set)
ver100_lawhs.ps created sucessfully.
finished
When a Maple worksheet is exported to html, a pretty good html copy of the worksheet is obtained which can then be posted to the web. This can be used to post solutions to homeworks, or for other uses. If you want to omit certain blocks of the worksheet, or otherwise modify the html export , this must be done by hand. Also, there is no way to conveniently tie together several worksheet into one html file without copying all the worksheet into one worksheet and exporting that to html. So it is not convenient to make a good html copy of a manual or set of class notes. The latextools package has some words that facilitate such tasks.
> | htmlit(Help=yes); |
htmlit("worksheet","c://temp/folder") removes dl indentation from
worksheet1.html, the preformatting tags <pre > and </pre > in textoutput,
and removes any html in an OMIT TIMO block. It also removes links to sections in
such a block from worksheetTOP.html
Options:
Help=yes will display this message.
Title="" Replace with the title of the worksheet in its TOC.
The word htmlit is like latexit, except it doesn't have as many options. When a worksheet, say mystuff is exported to html, several files are created. A small file mystuff.html is created which is the control file. Another small file, mystuffTOC.html contains links to all of the sections in the worksheet. It is the table of contents file. Then is one or more files mystuff1.html, mystuff2.html, ... which are created. These represent sections in the document. Everything that you can see in the worksheet when you export to html is put in the file mystuff1.html
When you point your browser to the file mystuff.html, you see two frames. On the left is a table of contents with links, and on the right is a frame which displays whichever link is active in the table of contents frame. This eases navigation in the document.
htmlit performs two main functions currently: First, it allows you to omit blocks of html from the document. The same blocks *OMIT/*TIMO blocks (replace *'s by underscores) that are omitted by latexit from the tex export are omitted by htmlit from the html export. Note: this is done only in sections which are open and occur in the main html sheet (mystuff1.html).
Second, it removes links in the table of contents sheet (mystuffTOC.html) which refer to sections which were omitted in OMIT/TIMO blocks.
> | htmlrootwork(Help=yes); |
htmlrootwork("rootname","path",Files=["file1","file2",..])
where rootname is the name you have chosen for the rootfile, path is
the path to the folder containing the html files, and
[file1,...] is the list of html files in the document. These should be
processed in advance with htmlit.
Options:
Help=no change to yes to get this message.
Index=no change to yes to create an index.
> |
The word
htmlrootwork
is like rootwork, except it doesn't have as many options. If you have a group of worksheets you have exported to html in the same directory, then you can make a 'root' html file and its accompanying TOC file with htmlrootwork. In this
If you have marked any terms in any of the worksheets with the
index character style
(the color must be dark green) so that an index item would be created in latex, a corresponding item is placed in an html index file which htmlrootwork creates.
> |
Managing the bookmarks in worksheets with mwsit
Go to the view menu at the top of Maple and click on Bookmarks. On a fresh worksheet, you won't see any listed. You can add bookmarks to the list (or delete them from the list) by an editor that is built in to Maple. This is hard to use and so not much use is made of bookmarks. The word mwsit is written to make bookmarking a more convenient operation. It takes all the index entries that you have made for the use of latexit and htmlit and makes them bookmarks. It also bookmarks every section you create with the text entry in that section header. If you decide that you want to remove the bookmarks later, you can use unmwsit . Here is the help message for mwsit
> | mwsit(Help=yes); |
mwsit("worksheet","path") Reconstructs the bookmarks of
the worksheet located in path. Sections and text marked with "index"
character style are bookmarked.
Use unmwsit("worksheet","path") to remove all bookmarks from
the worksheet.
Options (with defaults):
Help=no Help=yes will display this message.
Outfile="" Outfile = "bill" writes the worksheet to bill.mws in path.
BookMarkStyles=["index","bookmark","word"] is the list of characterstyles that bookmarks are in.
BookMarkLength=37: the first 37 characters of a bookmark are copied.
> |
Creating a Table of contents and index (Toci) worksheet with mwsrootwork
If you have a group of worksheets that you are using to some purpose, you can use
mwsrootwork
to make a management worksheet for the group. First, bookmark the worksheets in the group with mwsit. Choose a name for your management worksheet, say root and execute mwsrootwork("root",path,Files=["file1",...]);
Here is the help message for mwsrootwork
> | mwsrootwork(Help=yes); |
mwsrootwork("rootname","path",Files=["file1"])
where rootname is the name you have chosen for the root worksheet and
["file1",...] is the list (at least one) of worksheets in the document.
A worksheet rootname.mws is created. The section bookmarks from Files are used
to form a table of contents; the index bookmarks are used to form an index.
Sections which are closed are marked with a +. Note: If you just want to
see a listing of sections of a file, use show_sections("file","path");
Options:
Names=[] set to a list of names to use (Chapter 1 etc) in the root worksheet
Comments=[] set to a list of short (20 or so characters) descriptions of chapters
Separator=" .... " Change this if you don't like it.
Newroot=yes set to no if you want to keep the current root above the Table of Contents.
Toclevel=10 set to 3 to show the first three levels in table of contents.
Zip=no set to yes to zip the files into a zipfile named root.
set to only if that is all you want to do.
This word can be used to make a
'book of worksheets'
with a table of contents and index (
toci worksheet
) which for some purposes is more useful that the hardcopy postscript image and virtual html image you get from rootwork and htmlrootwork. To see an example see the Maple Handbook for calculus students at
http://www.msc.uky.edu/carl/Maple_Handbook/Maple_Handbook.htm
This word can also be used to make an table of contents for a group of WHS homework source worksheets
Note the Zip options. This is useful to create a zipfile of the book of worksheet you make with mwsrootwork. It presumes you have zip.exe in your path. All math sciences machines do. You can get it from the InfoZip Homepage. Put it into your winnt folder.
> |
show_sections: A non-creative way to list the sections in a worksheet without opening it.
Sometimes you might want simple listing of the sections in a worksheet, without opening it.
show_sections(file,path) will give the desired listing. Each closed section is marked with a plus sign + on the listing.
Note on navigation from the Table of contents worksheet:
Open the Table of contents worksheet. Then scan for the item you want to see, then click it. This opens the worksheet containing the item (at the item) and closes the table of contents worksheet. Read and work in this worksheet. When done, click the back arrow at the top of the worksheet (just under the word 'Window'). This will close the worksheet (giving you an opportunity to save it if you have work to save) and open the table of contents worksheet. I
> |
Troubleshooting, bugs, fixes, and improvements
The two html words htmlit and htmlrootwork ought to work right 95 percent of the time, since there are only limited options, and there are no external programs called to process the html. The two latex words latexit and rootwork are a different story. Each one has a lot of options, so you must expect to encounter problems each time you try a new option. Also, each word makes calls to latex and dvips to produce the dvi and postscript files. So you will need to examine the error messages carefully to determine whether the problem occurs in Maple or in those external programs. In either case the problem should be fixed in the source worksheet, if at all possible.
If a problem occurs with executing a bit of Maple code, I can usually discover the source by setting printlevel:=10 and re-executing. You get a peek at the background computations. Setting printlever to a higerer number gives a bigger peek. Set it back to 1 when you are done peeking.
A common error is to fail to execute the latextools package at the start of a session. If Maple does not know the definition of a procedure, such as latexit, then it will just spit your input back at you.
Another useful device is to toggle the Show invisible characters button in the View Menu. Sometimes you will introduce control characters into the worksheet, particularly into the text cells. These show up as empty square boxes when invisible characters are turned on. Get rid of these.
If a problem occurs with Latexing the files, you will see a black command window hang there with a question mark at the bottom. Just above that is a line number and some context (so that you can tell where in the file to look), together with a latex error message. Put an x into the command line and press enter. This will close the command window.
If you can figure out how to change the source worksheet so as to avoid that message (such as a document style is missing), do so. Otherwise, you will need to open the tex file (remember, it has a whs appended) in a text editor and go to that line and take a closer look. If you still can't decipher the problem, it just may be a bug in latextools. Drat.
As we mentioned at the outset, this is a first attempt, and the package has not been tested extensively. It has been used to produce this Manual, the Manual for WHS authors, and some homework extracted from WHS homeworks. Please report any bugs you discover in the process of using latextools to me (carl@ms.uky.edu), and I will attempt to fix them. Or, if you can read my Maple code, feel free to fix them yourself, and send me a copy of your fix. The same goes for any suggested improvements you might dream up. I know of plenty, and plan future versions.
_LATEX
\begin{thebibliography}{99}
\bibitem{kopka} Helmut Kopka and Patrick W. Daly, \textsl{A Guide to LaTex 2e} sec. ed., Addison-Wesley
\end{thebibliography}
_XETAL
\appendix
> |
> |
Here are the commands that were used to create the postscript and html versions of this manual. To make a pdf file of the postscript, load it into gsview and convert it to pdfwrite.
Each time the worksheet latextools.mws is exported latextools.tex execute this command.
> | latexit("latextools","c://carl/latextools"); |
index words duplicated
latextoolswhs.tex created
latextoolswhs.dvi created.
fixed eps files (removed their borders and recolored if Color=yes is set)
latextoolswhs.ps created sucessfully.
finished
> |
This command is only executed when you want to extract the tagit generated latex problems in the worksheet.
> | latexit("latextools","c://carl/latextools",WHSprobs=only,Head="WHS Problems from Latextools."); |
The latextools eps files are already recolorized.
latextools_la.tex created: 2 problems
The latextools eps files are already recolorized.
index words duplicated
latextools_lawhs.tex created
latextools_lawhs.dvi created.
latextools_lawhs.ps created sucessfully.
finished
> |
This command creates the manual from the two files latextoolswhs.tex and latextools_la.tex generated.
A frontpiece picture was chosen from the diagrams in the manual.
> | rootwork("latextools_manual","c://carl/latextools", Newroot=yes,Files=["latextoolswhs","latextools_la"], Title="Latextools Manual", Author="Carl Eberhart, carl\@ms.uky.edu\\\\Department of Mathematics, University of Kentucky",Mkindex=yes, Frontpiece=[3,4,"latextools_frontpiece"],Fonts=sanserif); |
rootfile created
latextoolswhs.tex rootified.
finished rotorootering.
latextools_la.tex rootified.
finished rotorootering.
added the files["latextoolswhs", "latextools_la"]
latextools_manual.dvi created
pass 2 to resolve references completed.
postscript file created.
This command creates a titlepage for the html version of the manual.
> | htmlit("latextools_titlepage","c://carl/latextools",Title="Title"); |
substitutions made
latextools_titlepageTOC.html filtered
This command filters the main manual worksheet.
> | htmlit("latextools","c://carl/latextools",Title="Latex Tools"); |
substitutions made
latextoolsTOC.html filtered
> |
This command creates the html manual.
> | htmlrootwork("Latex_Tools","c://carl/latextools", Files=["latextools_titlepage","latextools"],Index=yes); |
Latex_Tools_index.html created
root file created. Latex_Tools.html
> |
This command bookmarks the source worksheet latextools.mws.
> | mwsit("latextools","c://carl/latextools"); |
latextools.mws bookmarked.
> |
mwsrootwork creates a root worksheet Latex_Manual.mws with one chapter worksheet latextool.mws. We have added a titlepage worksheet, just to make it look like the postscript and html versions.
> | mwsrootwork("Latex_Manual","c://carl/latextools", Files=["latextools_titlepage","latextools"], Names=["Title","Manual"],Comments=["","A tutorial"], Separator=" ........ "); |
> |
The root worksheet Latex_Manual.mws is created.
Open it to check the Table of Contents and Index.
> |
mwszip makes a zipfile of the Manual and accompanying worksheets.
> | mwszip("Latex_Manual","c://carl/latextools", ["latextools_titlepage","latextools"]); |
A zipfile Latex_Manual.zip, containing Latex_Manual.mws, latextools_titlepage.mws, latextools.mws, has been created in c://carl/latextools.
> |
Predefined Docstyles, Preambles, Abbrevs, etc
These can be found in the latextools module. You can experiment with modifying them there. Or you can use the options provided to modify them.
DOCSTYLE:="[11pt]{article}":
DOCSTYLEAMS:="[11pt]{amsart}":
PKGS := {maple2e,color,latexsym,graphicx}:
PKGSAMS := {maple2e,amsthm,amsfonts,color,latexsym,graphicx}:
PSTYLE:= [["\\DefineParaStyle{prob}","\\DefineParaStyle{prob}"]]:
PSTYLEAMS := [["\\DefineParaStyle{prob}","%DefineParaStyle{prob}"],
["\\DefineParaStyle{lem}","%DefineParaStyle{lem}"],
["\\DefineParaStyle{thm}","%DefineParaStyle{thm}"]]:
SSFONTS:= "\\renewenvironment{Text Output}{\\small\\ttfamily\\mdseries}{}
\\renewcommand{\\ttdefault}{courier}
\\renewcommand{\\familydefault}{cmss}
\\mathversion{bold}":
FONTS:="":
LENGTHS:="% tweak these to taste.
\\AboveMapleSkip1 pt%- space above an environment
\\BelowMapleSkip 1 pt%- space bow an environment
\\AboveMaplePlot = 1\\AboveMapleSkip
\\BelowMaplePlot= 1\\BelowMapleSkip
% \\MaplePlotHeight - vertical space reserved for a plot
% \\MaplePlotWidth - width reserved for a plot
% \\MaplePlotAngle - angle of rotatation
% \\LeftMapleSkip - the amount of left indentation
% \\MapleFont - The Maple font
\\def\\MapleFont{\\ttfamily}
% \\MapleSize - The size of the Maple font in mapleinput and
\\def\\MapleSize{\\scriptsize}
% maplettyout
% \\MapleLatexSize- The size of the Maple fonts in maplelatex
\\def\\MapleLatexSize{\\small}
% \\MapleFirstLine- controls ingoring first line feed
% \\MaplePrompttrue - controls insertion of prompt char
% \\MaplePromptString= {\\raise 1pt \\hbox{\$\\scriptstyle>\$\\space}}
\\MaplePromptSecondary = {\\space\\space}
% \\MaplePromptSecondary- defines the secondary prompt string
% \\MapleSkip- amount of glue before and after
%displayed text
% \\MapleTab- number of spaces per tab (8)
\\def\\emptyline{\\vspace{6pt}}
\\setlength{\\oddsidemargin}{0in} \\setlength{\\evensidemargin}{0in}
\\textwidth 6.5in
\\topmargin 0in
\\textheight 8.5in
% You may need to add your own paragraph styles.
\\DefineParaStyle{Bullet Item}
\\DefineParaStyle{Heading 1}
\\DefineParaStyle{Heading 2}
\\DefineParaStyle{Heading 3}
\\DefineParaStyle{Heading 4}
\\DefineParaStyle{Comment}
\\DefineParaStyle{Problem}
\\DefineParaStyle{Definition}
\\DefineParaStyle{List Item}
\\DefineParaStyle{Dash Item}
\\DefineParaStyle{Title}
\\DefineParaStyle{Author}
\\DefineParaStyle{Warning}
\\DefineParaStyle{Mapleplot}
\\DefineParaStyle{Error}
\\DefineParaStyle{Diagnostic}
\\DefineParaStyle{Maple Output}
\\DefineCharStyle{2D Comment}
\\DefineCharStyle{2D Math}
\\DefineCharStyle{Help Heading}
\\DefineCharStyle{Hyperlink}":
MACROS:= "\\newcommand{\\Int}{\\displaystyle\\int}
\\newcommand{\\Lim}[2]{\\displaystyle\\lim}
\\newcommand{\\Frac}[2]{\\frac{\\textstyle #1}{\\textstyle #2}}":
PREAMBLE:= cat(LENGTHS,MACROS,"\n\\begin{document}");
AMSMACROS:=
"%\\swapnumbers
\\newtheorem{thm}{}[section]
\\newtheorem{lem}[thm]{Lemma}
\\newtheorem{cor}[thm]{Corollary}
\\theoremstyle{definition}
\\newtheorem{defn}{Definition}[section]
\\newtheorem{example}{Example}[section]
\\newtheorem{prob}{Problem}
\\theoremstyle{remark}
\\newtheorem*{rem}{Remark}
\\newtheorem*{note}{Note}":
PREAMBLEAMS:= cat(LENGTHS,MACROS,AMSMACROS,"\n\\begin{document}"):
ABBREVSAMS :=
[["\\_thm","\\begin{thm}"],["\\_mht","\\end{thm}"],
["\\_lem","\\begin{lem}"],["\\_mel","\\end{lem}"],
["\\_mf","\\mathfrak "],["\\_mc","\\mathcal "],
["\\_prf","\\begin{proof}"],["\\_frp","\\end{proof}"],
["\\TEXTsymbol{\\backslash}","\\"],["\\$","$"],
["\\_\\{","_{"],["\\TEXTsymbol{<}","<"],["\\TEXTsymbol{>}",">"],
["\\}","}"],["\\{","{"],
["\_wlt","\\prec\\!\\prec"],["\\frac ","\\Frac "],
["\\symbol{94}","^"],["\\lim _","\\Lim _"],
["\\symbol{126}","~"],["\\int _","\\Int _"],
["\\emptyline"," "]];
ABBREVS:= ABBREVSAMS:
> |