As you are hopefully beginning to see, troff provides you all the mechanisms you need for complete control over your document's format. Unfortunately, this is often more control than you need. Writing documents using bare troff, while possible, can be quite painful. It is very much like programming in assembly language: you have complete control, and when the result works it works really well, but there is an awful lot of detail to keep track of, and it can be tedious and difficult.
To make it easier for regular users to manage the detail, troff allows you to define macros. A macro is like a subroutine in a programming language. You can group commands together to perform a larger task, and use the macro name, instead of writing out the entire sequence of commands each time.
Consider starting a new paragraph. You have to do the following tasks:
1. See if there is room left on the page for at least two lines of text.
2. Skip a space after the last paragraph.
3. Indent the first line of text by 1/2 an inch.
You could write the commands to do this over and over again. But that is (a) tedious, (b) a hassle to update if you change how you do paragraphing. Instead, you can define a macro, say .P, to do this for you.
.de P \" DEfine paragraph macro .ne 3 \" we NEed at least three lines .sp \" SPace down one line .ti .5i \" Temporary Indent .5 inches .. \" end the macro definition
Then, in your text, you just put .P on a line by itself wherever you want a paragraph.
.ds LX the Linux Operating System .ds LJ \fILinux Journal\fP If you are new to \*(LX, then you should subscribe to \*(LJ. It covers \*(LX in great detail, month after month. .P And even if you are an experienced user of \*(LX, \*(LJ will bring you valuable tips and tricks to keep your Linux system up and running.
One of the less attractive features of standard troff is that command, macro, string, and register names are limited to no more than two characters. Fortunately, groff allows longer names, with a different syntax for accessing them. In fact, groff has many nice extensions over troff, making the task of writing macro packages considerably easier. The extensions are documented in the gtroff(1) man page.
There are a number of popular troff macro packages. Using them is like programming in FORTRAN; it beats the heck out of Assembly Language, but it's not as nice as C or Modula-3.
The common macro packages are:
-ms - Manuscript macros. Originated in V7, popular on Berkeley Unix.
-man - Manual Page macros.
-mm - Memorandum Macros. Very powerful macros, popular on System V.
-me - Berkeley Technical Paper macros. An ugly package.
-mdoc - The new Document Macros from Berkeley.
-mandoc - A package that figures out dynamically if you want -man or -mdoc.
groff will support these directly if you have them, particularly using the -C compatibility mode option. It also has its own version of many of these packages.
The -ms and -mm are the most portable packages to use. -mm has many more features than -ms, thus making it harder to learn. In the long run though, the effort is worth it, because you can do so much.
Over the years, it was found that macros helped, but that there were some things that were just too difficult to do in bare troff, even with macro packages. The approach that was developed was to write a “little language” that solved a particular task, and to pre-process the language into raw troff. The common pre-processors are:
tbl - formats tables
eqn - formats equations
pic - formats pictures (diagrams)
grap - formats graphs
As an example, here is part of a table from a reference card I worked on:
.TS tab(~); lfB l lfB l. abs~absolute value~int~integer part acos~arc cosine~log~natural logarithm asin~arc sine~sin~sine atan~arc tangent~sinh~hyperbolic sine cos~cosine~sqrt~square root cosh~hyperbolic cosine~tan~tangent .TE
We'll explain it line by line. First, tbl only looks at lines between .TS (table start) and .TE (table end). Everything else is left alone. This makes it easy to use tbl in a pipeline with the other preprocessors. The first line sets the tab character to ~. Normally, tabs in the input separate each column of the table. For this table, a ~ is used to make it easier to mark off the columns.
Then, for each line of data in the table, you provide a line that describes the layout information. l means left justified, r means right justified, and c means centered. All the columns in this table are left justified. The first and third columns also use a different font (the f). Here, they are using the bold font.
In this example, there is only one control line, so it is applied to all the data lines. For more complicated tables, you have one control line per data line, with the last control line applying to any remaining data lines.
The other preprocessors are similar in functionality. grap is actually a preprocessor for pic.
Typically, the commands are used in a pipeline:
grap doc.tr pic tbl eqn troff -mm -Tps > doc.ps
The actual usage will vary from machine to machine; we'll see below how to run groff.
Practical Task Scheduling Deployment
July 20, 2016 12:00 pm CDT
One of the best things about the UNIX environment (aside from being stable and efficient) is the vast array of software tools available to help you do your job. Traditionally, a UNIX tool does only one thing, but does that one thing very well. For example, grep is very easy to use and can search vast amounts of data quickly. The find tool can find a particular file or files based on all kinds of criteria. It's pretty easy to string these tools together to build even more powerful tools, such as a tool that finds all of the .log files in the /home directory and searches each one for a particular entry. This erector-set mentality allows UNIX system administrators to seem to always have the right tool for the job.
Cron traditionally has been considered another such a tool for job scheduling, but is it enough? This webinar considers that very question. The first part builds on a previous Geek Guide, Beyond Cron, and briefly describes how to know when it might be time to consider upgrading your job scheduling infrastructure. The second part presents an actual planning and implementation framework.
Join Linux Journal's Mike Diehl and Pat Cameron of Help Systems.
Free to Linux Journal readers.Register Now!
- Google's SwiftShader Released
- Interview with Patrick Volkerding
- SUSE LLC's SUSE Manager
- Tech Tip: Really Simple HTTP Server with Python
- My +1 Sword of Productivity
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- Returning Values from Bash Functions
- SuperTuxKart 0.9.2 Released
- Non-Linux FOSS: Caffeine!
- Managing Linux Using Puppet
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide