This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ProfessionalProcrastinator's profile picture

TypeCC - A Simple Typesetting System for Books

Started by ProfessionalProcrastinator, 21 November 2016 - 03:51 AM
ProfessionalProcrastinator #1
Posted 21 November 2016 - 04:51 AM
Writing a book with any kind of formatting can be cumbersome using the standard edit program. It becomes difficult to align text, make titles, properly create lists, and blockquotes? Fuggitaboutit!

CCType is a simple typesetting system that creates block-style paragraphs, ordered and unordered lists, titles, basic tables, and blockquotes easily. It allows you to preview and print multi-page documents, automatically handling word-wrapping, placement of paragraphs, and page breaks.

Just download the program, edit your document using an editor of your choice, and then run the CCType system:


cctype <filename>

SYNTAX
SpoilerThe syntax of CCType was inspired by Markdown, but is extremely simplified. Paragraphs are separated by double-enters; a single enter will be interpreted as a "hand-word-wrapped" paragraph, and the formatting will be discarded. Words will by wrapped by splitting on spaces and dashes.

Headers are represented like this:

## Header Text
#### Header Text ####
# Header Text ###
All three of these will be output as a center-justified header on the page. Word-wrapping will be applied if the header is wider than the page.

Ordered lists are represented as follows:

1. Item One
2. Item Two

3. Item Three
7. Item Four

Note that like markdown, items will be renumbered, so you can use 1 to signal every item in a list.

Unordered lists can be represented in one of several ways:

* Item one
* Item two
* Item three

- Item four
is lengthy
+ Item Five

+ Item Six
+ Item Seven
+ Item eight
is very long

All of these characters are interchangable.

Blockquotes can contain any combination of elements: block paragraphs, ordered and unordered lists, and even other blockquotes. They are represented as follows:


> This paragraph is a blockquote.
>It spans multiple lines.

> This multiple-line paragraph
doesn't require another bracket.

> 1. This is a
> 2. list inside of
> 3. a blockquote.
>
>This paragraph is in the same blockquote.

Page breaks are special: they are not rendered, but just force the paginator to create a new page if the current page is not empty.
They are written as two or more forward-slash ("/") characters, e.g.

//

/////

////
Note that page breaks cannot be included inside of blockquotes.

Tables are vastly simplified from many Markdown table implementations simply due to code size. I also had to take typesetting into account, which most Markdown implementations need not consider, since they are just concerned with generating markup.

Each table consists of one or more columns. Each row must have the same number of columns. If the cell counts don't match, the system will present an "[improper formatting]" message on the document.

All columns are evenly spaced. Each column must have at least 5 spaces of content width. If there are too many columns, the system will simply present a "[too many table columns]" message on the document.

Alignments can be specified as left, right, or center by filling the cells in the first row with dashes with colons on either side.

All this can be difficult to visualize, so I'll present a few examples.


A properly formatted table:

|This table has content.|It will be word-wrapped.|
|This content|is shorter.|

A properly formatted table with alignments:

|:--|:--:|--:|
|This cell is left-aligned.|This cell is center-aligned.|This cell is right-aligned.|

An unbalanced table:

|This row|has two columns.|
|This row|has three| columns.|
You can hand-align tables to be an even width; any leading or trailing spaces will be trimmed.

NOTE: Tables can be embedded into blockquotes, but not into lists or other tables.

PREVIEW
SpoilerWhat good would this program be if you couldn't check your work before printing? CCType comes with a simple preview system with edit-style controls and a MS-Word style view.

Here is an example document, taken from P.G. Wodehouse's "Carry On Jeeves":

# My Man Jeeves #

# P.G. Wodehouse #

# 1919 #

///

# LEAVE IT TO JEEVES #

Jeeves-my man, you know-is really a most extraordinary chap. So capable. Honestly, I shouldn't know what to do without him. On broader lines he's like those chappies who sit peering sadly over the marble battlements at the Pennsylvania Station in the place marked "Inquiries." You know the Johnnies I mean. You go up to them and say: "When's the next train for Melonsquashville, Tennessee?" and they reply, without stopping to think, "Two-forty-three, track ten, change at San Francisco." And they're right every time. Well, Jeeves gives you just the same impression of omniscience.

As an instance of what I mean, I remember meeting Monty Byng in Bond Street one morning, looking the last word in a grey check suit, and I felt I should never be happy till I had one like it. I dug the address of the tailors out of him, and had them working on the thing inside the hour.

"Jeeves," I said that evening. "I'm getting a check suit like that one of Mr. Byng's."

"Injudicious, sir," he said firmly. "It will not become you."

"What absolute rot! It's the soundest thing I've struck for years."

"Unsuitable for you, sir."

Well, the long and the short of it was that the confounded thing came home, and I put it on, and when I caught sight of myself in the glass I nearly swooned. Jeeves was perfectly right. I looked a cross between a music-hall comedian and a cheap bookie. Yet Monty had looked fine in absolutely the same stuff. These things are just Life's mysteries, and that's all there is to it.

But it isn't only that Jeeves's judgment about clothes is infallible, though, of course, that's really the main thing. The man knows everything. There was the matter of that tip on the "Lincolnshire." I forget now how I got it, but it had the aspect of being the real, red-hot tabasco.

"Jeeves," I said, for I'm fond of the man, and like to do him a good turn when I can, "if you want to make a bit of money have something on Wonderchild for the 'Lincolnshire.'"

He shook his head.

"I'd rather not, sir."

"But it's the straight goods. I'm going to put my shirt on him."

"I do not recommend it, sir. The animal is not intended to win. Second place is what the stable is after."

Perfect piffle, I thought, of course. How the deuce could Jeeves know anything about it? Still, you know what happened. Wonderchild led till he was breathing on the wire, and then Banana Fritter came along and nosed him out. I went straight home and rang for Jeeves.

"After this," I said, "not another step for me without your advice. From now on consider yourself the brains of the establishment."

"Very good, sir. I shall endeavour to give satisfaction."

And he has, by Jove! I'm a bit short on brain myself; the old bean would appear to have been constructed more for ornament than for use, don't you know; but give me five minutes to talk the thing over with Jeeves, and I'm game to advise any one about anything. And that's why, when Bruce Corcoran came to me with his troubles, my first act was to ring the bell and put it up to the lad with the bulging forehead.

"Leave it to Jeeves," I said.

I first got to know Corky when I came to New York. He was a pal of my cousin Gussie, who was in with a lot of people down Washington Square way. I don't know if I ever told you about it, but the reason why I left England was because I was sent over by my Aunt Agatha to try to stop young Gussie marrying a girl on the vaudeville stage, and I got the whole thing so mixed up that I decided that it would be a sound scheme for me to stop on in America for a bit instead of going back and having long cosy chats about the thing with aunt. So I sent Jeeves out to find a decent apartment, and settled down for a bit of exile. I'm bound to say that New York's a topping place to be exiled in. Everybody was awfully good to me, and there seemed to be plenty of things going on, and I'm a wealthy bird, so everything was fine. Chappies introduced me to other chappies, and so on and so forth, and it wasn't long before I knew squads of the right sort, some who rolled in dollars in houses up by the Park, and others who lived with the gas turned down mostly around Washington Square-artists and writers and so forth. Brainy coves.

Corky was one of the artists. A portrait-painter, he called himself, but he hadn't painted any portraits. He was sitting on the side-lines with a blanket over his shoulders, waiting for a chance to get into the game. You see, the catch about portrait-painting-I've looked into the thing a bit-is that you can't start painting portraits till people come along and ask you to, and they won't come and ask you to until you've painted a lot first. This makes it kind of difficult for a chappie. Corky managed to get along by drawing an occasional picture for the comic papers-he had rather a gift for funny stuff when he got a good idea-and doing bedsteads and chairs and things for the advertisements. His principal source of income, however, was derived from biting the ear of a rich uncle-one Alexander Worple, who was in the jute business. I'm a bit foggy as to what jute is, but it's apparently something the populace is pretty keen on, for Mr. Worple had made quite an indecently large stack out of it.

See how much horizontal space that takes up? Here is an example of a preview of this document:



Much better! You can use the arrow keys or pg-up and pg-down keys to navigate the document. When you're ready to print (or exit), just press ctrl, and a familiar menu will greet you.



When you select print, the preview will close, and your printer will begin printing. Note: if your document takes up more than six pages, the program will hang until all pages are ended. I suggest using a hopper into a chest in this case. Every page is titled as "<filename>: page <#>", so reordering them is easy.

Tables are complex enough to warrant their own screenshots.


# Store Prices #

|:-|-:|
|Eggs|1 nugget|
|Chest|2 nuggets|
|Sword|3 nuggets|
|Iron Armor|4 gold ingots



Please let me know what you think!

Pastebin: ppySQ4xY
Edited on 29 December 2016 - 05:36 PM
AlexDevs #2
Posted 21 November 2016 - 06:06 PM
Wow nice!
Exerro #3
Posted 21 November 2016 - 07:00 PM
Yeah, wow. It's simple to use, nicely documented and explained, and has (from what I can tell) a nice, intuitive UI. Even the code has better comments than half the documentation I've written.

Bold text would be nice. As far as I'm aware, you can print text in multiple colours, so supporting grey text for normal text and black for bold might be worth doing. Tables are probably possible too, and might be useful for things like an item/price list in a shop.
ProfessionalProcrastinator #4
Posted 22 November 2016 - 03:47 AM
Bold text would be nice. As far as I'm aware, you can print text in multiple colours, so supporting grey text for normal text and black for bold might be worth doing. Tables are probably possible too, and might be useful for things like an item/price list in a shop.

Printing in multiple colors requires taking page, printing one color, using a turtle to swap out ink and move the printed page to the top tray, and printing another layer. It could be possible, but would require much more hardware; I want this to be possible using just a computer (btw, it works on regular computers too; I forgot to mention that) and a printer.

Tables are an interesting idea. You're right, they would be good for item shops, but the problem is that a page can only be 25 characters wide; for more than short lines with two columns, there would be a lot of word-wrapping involved, and that might involve splitting in the middle of words (which would complicate part of the code, but only part of it). It would be tricky, but doable and perhaps worthwhile. I'll have to experiment.
Lupus590 #5
Posted 22 November 2016 - 09:42 AM
Printing in multiple colors requires taking page, printing one color, using a turtle to swap out ink and move the printed page to the top tray, and printing another layer. It could be possible, but would require much more hardware;

http://www.computercraft.info/forums2/index.php?/topic/4515-142apimulticolor-printer-api-mcp/
thecrimulo #6
Posted 24 November 2016 - 10:58 PM
I suppose you can't print JSON to it to make colors and bold?

Anyways, this is great and I appreciate it, good job!
ProfessionalProcrastinator #7
Posted 29 December 2016 - 06:37 PM
I updated it to add tables, plus abstracted out word-wrapping a little more and fixed some problems with long words and narrow columns.