⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tt10

📁 unix v7是最后一个广泛发布的研究型UNIX版本
💻
字号:
.NHNumber Registers and Arithmetic.PP.UL troffhas a facility for doing arithmetic,and for defining and using variables with numeric values,called.ulnumber registers.Number registers, like strings and macros, can be useful in setting up a documentso it is easy to change later.And of course they serve for any sort of arithmetic computation..PPLike strings, number registers have one or two character names.They are set by the.BD .nrcommand,and are referenced anywhere by.BD \enx(one character name) or.BD \en(xy(two character name)..PPThere are quite a few pre-defined number registers maintained by.UL troff ,among them.BD %for the current page number;.BD nlfor the current vertical position on the page;.BD dy ,.BD moand.BD yrfor the current day, month and year; and.BD .sand.BD .ffor the current size and font.(The font is a number from 1 to 4.)Any of these can be used in computations like any other register,but some, like.BD .sand.BD .f ,cannot be changed with.BD .nr ..PPAs an example of the use of number registers,in the.BD \-msmacro package [4],most significant parameters are defined in terms of the valuesof a handful of number registers.These include the point size for text, the vertical spacing,and the line and title lengths.To set the point size and vertical spacing for the following paragraphs, for example, a user may say.P1^nr PS 9^nr VS 11.P2The paragraph macro.BD .PPis defined (roughly) as follows:.P1.ta  1i^de PP^ps \e\en(PS	\e" reset size^vs \e\en(VSp	\e" spacing^ft R	\e" font^sp 0.5v	\e" half a line^ti +3m^^.P2This sets the font to Roman and the point size and line spacingto whatever values are stored in the number registers.BD PSand.BD VS ..PPWhy are there two backslashes?This is the eternal problem of how to quote a quote.When.UL trofforiginally reads the macro definition,it peels off one backslashto see what's coming next.To ensure that another is left in the definition when the macro is.ulused,we have to put in two backslashes in the definition.If only one backslash is used, point size and vertical spacing will be frozen at the time the macrois defined, not when it is used..PPProtecting by an extra layer of backslashesis only needed for.BD \en ,.BD \e* ,.BD \e$(which we haven't come to yet),and.BD \eitself.Things like.BD \es ,.BD \ef ,.BD \eh ,.BD \ev ,and so on do not need an extra backslash,since they are converted by.UL troffto an internal code immediately upon being seen..WS.PPArithmetic expressions can appear anywhere thata number is expected.As a trivial example,.P1^nr PS \e\en(PS\-2.P2decrements PS by 2.Expressions can use the arithmetic operators +, \-, *, /, % (mod),the relational operators >, >=, <, <=, =, and != (not equal),and parentheses..PPAlthough the arithmetic we have done so farhas been straightforward,more complicated things are somewhat tricky.First,number registers hold only integers..UL troffarithmetic uses truncating integer division, just like Fortran.Second, in the absence of parentheses,evaluation is done left-to-rightwithout any operator precedence(including relational operators).Thus.P17*\-4+3/13.P2becomes `\-1'.Number registers can occur anywhere in an expression,and so can scale indicators like.BD p ,.BD i ,.BD m ,and so on (but no spaces).Although integer division causes truncation,each number and its scale indicator is convertedto machine units (1/432 inch) before any arithmetic is done,so1i/2uevaluates to0.5icorrectly..PPThe scale indicator.BD uoften has to appearwhen you wouldn't expect it _in particular, when arithmetic is being donein a context that implies horizontal or vertical dimensions.For example,.P1^ll 7/2i.P2would seem obvious enough _3\(12 inches.Sorry.Remember that the default units for horizontal parameters like.BD .llare ems.That's really `7 ems / 2 inches',and when translated into machine units, it becomes zero.How about.P1^ll 7i/2.P2Sorry, still no good _the `2' is `2 ems', so `7i/2' is small,although not zero.You.ulmustuse.P1^ll 7i/2u.P2So again, a safe rule is toattach a scale indicator to every number,even constants..PPFor arithmetic done within a.BD .nrcommand,there is no implication of horizontal or vertical dimension,so the default units are `units',and 7i/2 and 7i/2umean the same thing.Thus.P1^nr ll 7i/2^ll \e\en(llu.P2does just what you want,so long as youdon't forget the.BD uon the.BD .llcommand.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -