Home
1 Introduction 2 How to learn to use mweb 3 Notes on using mweb
Contents
1. gt set L XData 1b 1 1 1le 1 1 22209 YData 1b 1 2 1le 1 2 pId s9 ese ar aner gt set gcf WindowButtonUpFcn BEN DME eM os set L Color 7 r 3 gt set gcf WindowButtonMotionFen 3 3 2T 5 The WindowButtonDownFcn determines the mouse position and creates a line whose begin and endpoints are the same create the line 5 lb get gca CurrentPoint le lb L line lb 1 1 le 1 1 2b 1 2 le 1 2 EraseMode xor This code is used in sections 3 and 8 6 Then the WindowButtonMotionFcn makes the endpoint of the line move with the mouse pointer reset the line 6 le get gca CurrentPoint set L XData lb 1 1 le 1 1 YData b 1 2 le 1 2 This code is used in section 3 7 And at last the WindowButtonUpFcn changes the colour of the line and by undefining the WindowButtonMotionFcn fixes it define fiz_line set L Color r 8 More examples The following code is just an example of several Matlab constructs it does nothing useful unused code 9 create the line 5 a variable amp with amp a com amp pound_name 8 9 Complex constants in Matlab are made by appending an i character In exponential notation it follows the exponent unused code 9 a 21 z 2 104 3 10 flarp rand
2. 38 8 linspace 3 8 some refinement 13 See also sections 10 11 12 16 and 17 This code is used in section 8 MWEB User Manual 7 10 Here a macro argument is used in a formatted string that is part of the replacement text of the macro This isn t useful it s just an example define print_arg win fun arg set win DeleteFcn lt fun arg gt unused code 9 print_arg gcf disp aargh print_arg gca fprintf foo 11 Array elements may be separated by commas or spaces or both unused code 9 x 0 0 2 7 2x2 2x7 5 4 5 20 9243857 oo a 1 4 aa 1 25 10 3 54 101 b 2 102 c T 4 12 if elseif else end constructs unused code 9 if a b a b 1 end if a b a b 1 end ifa b a b end if a 3 a b elseif a 4 a b 2 elsea a 1 end if a b a lt cV c gt 30 zora lt 3 some refinement 13 elseif a 25 c 4 67 2 8 6 3 elseif a lt b c ct3 else disp foo end end 13 A terrible for statement some refinement 13 for i 1 10 for j 1 5 6 for k 1 3 4 23 24 83 34 34 23 25 25 27 56 25 45 3 5 9 3 6 234 56 32324 m 432 234 453 345 345 93 93 83 i j 8 9 10 54 843 845 8342 7234 7834 matrix zeros 21 20 vect 4 matrix 2 i 1 7 end ifa b a at 2 end end end This code is used in sections 9 and 12 MWEB User Manual 8 14 C
3. MWEB User Manual Mark Potse May 22 2000 1 Introduction MWEB is a literate programming system like WEB 1 2 3 made for the MATLAB programming language 4 5 It is created with the Spider system and therefore it closely resembles Levy s CWEB 6 and many spidery webs There are spidery webs for ada awk C postscript turing and several others This article describes how to learn using MWEB If you want to learn what Literate Programming is the best thing to do is read the article Literate Programming by D E Knuth 3 or the book by the same name 2 2 How to learn to use mweb Writing a comprehensive user manual takes a lot of time more than the author of MWEB can afford to spend on it Fortunately there is the Spidery WEB User Manual 7 the common user manual for all WEBs of the Spider class Most of the material in there applies to MWEB To learn using MWEB read that manual and afterwards read section 3 and perhaps the appendices of this document 3 Notes on using mweb The following are features of MWEB that are not present in any Spidery web These include language specific features bells and whistles that are only useful in MATLAB code and fixes to the private version of Spider that are not present in the official version The latter include bug fixes as well as extra features e It is very difficult for mweave and mtangle to see if a quote is a transpose operator or a string delimiter In test progr
4. acro for example to save time in tight loops e Comments introduced with a percent sign are ignored by mtangle If you want a comment to be printed in the m file for example to make a comment block for MATLAB s help function you can use instead of This creates a comment that is copied verbatim to the m file and is printed in typewriter type by mweave MWEB User Manual 3 e The special identifier TeX can be used in format definitions like in CWEB If one defines format foo TeX then the identifier foo will be printed as the TFX control sequence foo by mweave A definition for this control sequence may be provided in the limbo section or may be standard in plain TFX or ATEX e g for the identifier phi which becomes phi which prints as Note that the control sequence will be used in math mode By this mechanism an identifier can be made to look like anything e Some Spider bugs were fixed Prevent multiple occurrences of sections in cross reference lists TEX s special characters are protected in output files and full support for other languages than English e The s control sequence from CWEB will be implemented 4 An example As an example I present here an MWEB document that is short enough to read but long enough to get a feel of how it works The following sections contain e an excerpt from the web file the source of all e an excerpt from the m file produced by mtangle e an excerpt from
5. ams it all goes quite well now but there may be errors still If you have problems with this i e if MWEB thinks a transpose operator is a string delimiter or v v you can put the string and its delimiters in parentheses some sillyystring put the argument of the transpose operator in parentheses a This should always work If you get the error message unknown left context for qoute mweave could not decide on the question Please inform the author about this particularly about the context involved In such cases mweave will assume it is a transpose operator as a default and in most cases you can solve the problem with parentheses as stated above e MWEB can be used with TFX instead of TeX by means of the webfiles package 8 e Strings opening with a left quote are typeset as normal code by mweave mtangle translates the left quote to a normal quote and does macro expansion and module expansion inside the string This is useful if you write strings containing MATLAB code as is done a great deal in user interface stuff You get prettyprinted code identifiers are indexed and you can use modules and macros in lWith webfiles you can import any number of WEB documents from mweave cweave and several others in a single IATFX document and of course use IATFX as the documentation language in the WEB documents themselves MWEB User Manual 2 the string You can even use these
6. eful it s just an example Y P 4 D print _arg wint fun arg s 5 set 1 wink 39 DeleteFcn 39 FQL 1 fun 1 f arg 2 FQR 2 2 par Y P 4 X9 unused code X mathrel S 6 print _arg 1 fgcf 39 disp 39 aargh 2 Y par print _arg 1 gca 39 printf 39 foo 2 Y par fi M11 Array elements may be separated by commas or spaces or both Y P 4 X9 unused code X mathrel S 6 x 1 0 0 OLO O 2 pi 3 39 0 2 0 2 39 0 2 pi 5 39 0 5 39 0 4 5 O 20 0 9243857 infty 2 6 a 0 1 0 4 6 aa 0 1 25 _4 0 3 54 _10 6 b O 2 _20 I it 6 Cc pi 0 4 Y par fi MWEB User Manual 5 D The documentation of example This is the final document It was typeset using the webfiles package 8 Example Section Page Example si 98 s ob iaa rE pee eed A eed Peden bee E EREA oes 1 5 Formatted Strings zi 2 si dks adie e a aa Aa eds Sane Aa o AAEE ee 3 5 More exam ples eseri decd ede ie ei a Rt ee ee ee 8 6 Custom formatting of identifiers 0 0 cnet 14 8 1 Example This file serves to test MWEB Matlab Web and to illustrate its features 2 This code is written in a file called lines m This function creates a figure window where lines can be drawn interactively by pushing the left mouse butt
7. formatted strings in macro replacement texts and have macro arguments expanded inside To create a formatted string inside another formatted string use another single left quote and close it with a single right quote To create a normal string or a transpose operator inside a formatted string use a double quote character These rules apply also in modules that are used in the string and to macro arguments that are used in a formatted string in the macro s replacement text Line continuations may be used in the formatted string to enable mweave to parse the text correctly they are ignored by mtangle The left and right quotes in a formatted string must be balanced Opening and closing quotes are typeset using the FQL and FQR macros These are defined in mweb tex They expand into n left or right quotes where n is the string s nesting level There are two versions of the FQL and FQR macros in mweb tex the author prefers the version that uses guillemets instead of quotes but this requires a nonstandard font Of course you can redefine them to whatever you like Note that although a formatted string can contain newlines MATLAB strings cannot The newline characters are removed by mtangle This means that you must sometimes add a comma or semi colon as appropriate to keep the interpreter happy in places where a newline would be enough in normal code Also line continuation tokens are not necessary to make the te
8. on at the desired begin point dragging the mouse and releasing the button at the desired end point lines m 2 figure axes Units normal Position 0 0 1 1 Visible off XLim 0 1 YLim 0 1 XLimMode manual YLimMode manual set the callbacks 3 3 Formatted strings Particularly when creating a user interface Matlab programmers may want to write nested strings containing code up to three or four levels This example program defines a WindowButtonDownFcn which in turn defines a WindowButtonMotionF cn and a WindowButtonUpFcn which in turn undefines the WindowButtonMotionFcn Some parts of the code are put in refinements to keep this section comprehensible set the callbacks 3 set gcf WindowButtonDownFcn lt create the line 5 set gcf WindowButtonMotionFcn reset the line 6 set gcf WindowButtonUpFcn fiz_line set gcf WindowButtonMotionFcn gt This code is used in section 2 MWEB User Manual 6 4 By the way mtangle expands the above code into set gcf WindowButtonDownFcn 1lb get gca CurrentPoint zkers TDS 2 gts se L line 1b 1 1 1le 1 1 1b 1 2 1e 1 2 gt FraseMode xor gt set gcf WindowButtonMotionFcn le get gca CurrentPoint
9. the tex file produced by mweave and e the resulting documentation MWEB User Manual 4 A An excerpt from example web Here is the source of it all starting at module 10 Note that the indentation used by the author which is used to enhance readability of the web file itself is ignored by mweave Here a macro argument is used in a formatted string that is part of the replacement text of the macro This isn t useful it s just an example d print_arg win fun arg set win DeleteFcn fun arg lt unused code gt print_arg gcf disp aargh print_arg gca printf foo Array elements may be separated by commas or spaces or both lt unused code gt x 0 0 2 pi 2 2 2 pi 5 4 5 20 9243857 inf a 1 4 aa 1 25e4 3 54F10 b 2e20i1 c pi 4 B An excerpt from example m Here is a small part of the lines m file that mtangle produces corresponding to the web text above set gcf DeleteFcn disp aargh set gca DeleteFcn printf foo x 00 2 pi 2 2 2 pi 5 4 5 20 9243857 inf a 1 4 aa 1 25e4 3 54E10 b 2e20i c pi 4 C An excerpt from example tex The tex file that is output by mweave is not meant for human readers although it can perfectly well be handled by T X M10 Here a macro argument is used in a formatted string that is part of the replacement text of the macro This isn t us
10. tion 2 some refinement 13 Used in sections 9 and 12 unused code 9 10 11 12 16 17 gcf 3 10 get 5 6 lb 5 6 le 5 6 line 5 linspace 9 matrix 13 Pin 14 pound name 8 print arg 10 rand 9 set 3 6 7 10 TeX 14 15 vect 13 win 10 with 8 zor 12 zeros 13 Used in section 8 MWEB User Manual 10 References 1 Donald E Knuth Literate programming The Computer Journal 27 1 97 111 1984 2 Donald E Knuth Literate Programming CSLI 1992 CSLI Lecture notes no 27 3 Donald E Knuth The WEB system of structured documentation Stanford University 1983 Computer Science Report CS980 4 The Math Works Inc Cochituate Place 24 Prime Park Way Natick Mass 01780 USA Matlab User s Guide August 1992 5 The Math Works Inc Cochituate Place 24 Prime Park Way Natick Mass 01780 USA Matlab Reference Guide August 1992 6 Sylvio Levy The CWEB System of Structured Documentation 7 Norman Ramsey The Spidery WEB system of Structured Documentation 8 Mark Potse The webfiles Style Option september 1994
11. ustom formatting of identifiers In the limbo section of this file the following definition was made def phin phi_ rm in Which prints as gin Then the variable that is typed as phin in the program prints as in too if the following format statement is used format phin TeX 15 We also want the identifier beta to print as 3 Because this definition is already provided by plain TFX and ETRX we need not give it here we just have to use the following format statement format beta TeX 16 This is the result The identifier alpha is not treated specially so it is printed in the usual way unused code 9 din alpha b MWEB User Manual 17 Switch statements are new in Matlab version 5 Here is a pathological case unused code 9 switch a_variable a_variable_with_a_long_name 23239847 1 24 10 34 1 a b0 2 4c case 0 c 3 b a c 2 24 z case 1 a 2 case 2 3 4 a 3 otherwise a 4 5 end Index of example at hat index entry 13 at period index entry 13 a com 8 a_variable 17 a_variable 8 a_variable_with_along name 17 aa 1l alpha 16 arg 10 azes 2 p 15 disp 10 12 figure 2 fiz_line 3 7 flarp 9 fprintf 10 fun 10 gca 5 6 10 List of Refinements in example lines m 2 create the line 5 Used in sections 3 and 8 reset the line 6 Used in section 3 set the callbacks 3 Used in sec
12. xt correct for MATLAB but they may be necessary to mweave mtangle translates a formatted string into a concatenation of strings one for each line in the web file in order not to overflow MATLAB s input buffer The final result that is what gets evaluated by MATLAB is a single string in MATLAB s memory Note also that this feature allows you to be very unreasonable to your computer with great ease If you type after typing ie in a string at level 6 it prints as 7 left quotes and is tangled into 2999999999999 9999999999999999999999999999999999999999999999999929 2 quotes mtangle can handle nested formatted strings upto at least level 15 which yields 16384 quotes in the output MATLAB seems to have an input buffer of 1024 characters a single line of code may not be longer than that Examples of the use of formatted strings are given in appendix D The complete source of this appendix is in the file example web e You can give string arguments to macros which get inserted in a normal string i e not a formatted string as discussed above in the expansion text The argument called foo is referred to as foo in the string for example d a_macro str disp the string is str a_macro hello is tangled into disp the string is hello This can circumvent the use of the sprintf function when a constant string argument is given to a m
Download Pdf Manuals
Related Search
Related Contents
Válvula U お客様各位 BDマイクロファインプラスと各社ペン型注入器の組み合わせ AT&T E2801 User's Manual ドライバー仕様書 - シチズン・システムズ Tobii Dynavox I-Series+ Manual do usuário DC 9 64A (10-76) Canon i-SENSYS LBP6300 Lenovo ThinkCentre E73z Exhibitor Service and Rental Order Forms Copyright © All rights reserved.
Failed to retrieve file