PART III: Abstracting the format

And finally, we get to the point of all this.

Style Sheets:

Now that we have a usable page, the real fun begins... Now we want to abstract this border into a style, so that with 1 option we can immutably add this border to any page.

What is a style?

When I heard about “styles” I was thinking mainly of fonts and stuff. Ends up that “styles” can be macros that dump text or images or whatever into your document. If you don't know what that means, it means that they can be pretty powerfull.

DRAFT COPY - do not slashdot this article

This is a draft version of a upcomming article. It is not yet finished. Please do not slashdot this article untill it is finished, and put under 'realeased articles'

How do we make a style?

Go read style-example.en.tm, which for me is in TeXmacs-1.0.4.1-static-gnu-linux/doc/devel/style/design/style-example.en.tm

It's not as bad as it sounds. It's a 2 page document, which starts you out on how to define a style. As for writing style contents, your in a GUI editor when your in texmacs! Just make what you want on the screen, then document->view->edit source tree to view the code. Then highlight the code, copy, switch to your style definition file and paste :)

What do we want in *our* style file? a couple of things:

  1. Something to auto-set the colors
  2. We want a macro called left-border that'll be the left border
  3. We want a macro called right-border that'll be the right border
  4. We want a macro called top-border . 3 guesses what it'll be
  5. We want a macro called bottom-border

Autosetting the colors is pretty easy. (note, this is only usefull with my html ”color patch”). Start by creating a new style file (you should already have one from the “style example“ above, so you can just use that). I call mine webchunk3.ts and store it in ~/.TeXmacs/packages/

Now add the following to the begining of the file:

<assign|bg-color|black>

<assign|color|orange>

Obviously use differnt colors if you don't want orange on black.

Now save the file. Next create a new file, and pick document->add package->{whatever name you just saved under}. As soon as you add the package, it should change colors to whatever you set it to.

A cool trick:

If you know scheme, try document->view->style->scheme, but everywhere i talk about <operator|value1|value2> you should read (operator “value1” “value2”).

The documentation:

Were getting pretty close to the end. You may want to read help->manual->writing your own style files, to help understand what your doing in the rest of the document.

Probing:

Often you'll be looking for a specific function when developing a macro. One of the best ways to find and insert them, it to probe the system. To do this, just create a new document, and create the situation that your looking for inside your document. Then click Document->View->Edit source tree. What your looking for should be somewhere in there.

Now also notice:

  • You can always insert something as \{whatever function you wanted}{enter}, so like \assign{enter} would create a assign statement.
  • Even when in “source mode”, and while working on a macro, the menu options still work on insert & moddify items inside the macro. This is hugely usefull

Interpeted environments (ones in which you don't have to compile before seeing results), always make probing much easier. So might as well make use of it :)

DRAFT COPY - do not slashdot this article

This is a draft version of a upcomming article. It is not yet finished. Please do not slashdot this article untill it is finished, and put under 'realeased articles'

Abstracting our spaces:

Now the document has a tendancy to ram all together, with no vertical skips. we've already talked about inserting gif's as spacers, but that's kinda a pain in the ass to do at each section start. How do we handle it easier? Make a new macro in our style sheet!

I created 2 macros for myself. one called ”partz”, and another called, “sectionz”. They insert spaces, and set the justification how i want for the “part headdings” and “section headdings” accordingly. These names have a wierd “z“ on the end of them, because i didn't know if my definitions would collide with normal “section” definitions.

Mine look like this:

<assign|partz|<macro|body|<with|par-mode|center|<tabular|<tformat|<table|
<row|<cell|<postscript|spacer-v-100.gif|*5/8|*5/8||||>>>|
<row|<cell|<surround|PART ||<arg|body>>>>|
<row|<cell|<postscript|spacer-v-100.gif|*5/8|*5/8||||>>>>>>>>> 

<assign|sectionz|<macro|body|<with|par-mode|left|
<surround||<postscript|spacer-v-070.gif|*5/8|*5/8||||>|
<surround||:|<arg|body>>>>>>

But obviuosly it's easier to make the contents in the GUI editor.

Another cool trick:

to gain access to functions provided by modules while “probing” what they do, try opening a scheme session, and try something like this:

scheme]

(texmacs-module (convert xx yy) (:use (convert tools tmcolor)))

scheme]

tmcolor->list

#<procedure tmcolor->list (c)>

scheme]

Obviously xx and yy are just “bluffing” vars, and after “use” you should put the module name of the file your looking to probe. I don't know if this is “ethical”, but it works, and thus can be usefull for probing.

–Endgame–:

Now making a table for every page you write is a pain in the ass, so we could make it once, and use that as a template for all your other pages... But that's the compsoer way of doing things! The borders would be abstracted, but the table would not, so if we made structural changed to the table, we would have to update every page!

So here's what you do: Make a new page. Document->Add package->* (for me it's “webchunk3”). Make a table, add a left border, a right border, and a bottom border, etc. type “ahh! My spine!” in as your “body text”. Then go to your style sheet. do ‘<assign|my-web-page|<macro|body|> >. Then change your new page to source format with Document->View->Edit source tree. Highlight the entire thing, hit, copy, then paste it in as the last parameter of the macro.

Now you ahev a macro that will say “Ahh! My spine!”, and only that, on every web page. What good is that? Go edit remove “Ahh! My spine!” with \body. (it was the name we gave as the first parameter we handed the macro).

Now, create a new texmacs document. Pick Document->Add package->*, then type \my-web-page. The document will turn to the web page art you wanted, with the cursor flashing in the center waiting for you to enter whatever body text you may think of, a. This is exactly what we wanted all along.

We win! yay.

Where to go from here:

This document is no where near complete in showing you everything you can do with webpages. It's just meant to get you started, and get you familiar with it enough to enable you to get what *you* want out of texmacs. The full styleguide in help->manual->writing your own style files, will be a invaluable reference as you continue to explore the possibilities of texmacs. What follows is a list of ideas, of where one could go from here, depneding on ones individual needs.

DRAFT COPY - do not slashdot this article

This is a draft version of a upcomming article. It is not yet finished. Please do not slashdot this article untill it is finished, and put under 'realeased articles'

Ideas of things to play with in the future:

  • We could make the table cells vertical justify to the top, center, or bottom, depending on how it was set in texmacs Table->Special cell properties->hyphenation menu
  • We could make the colors dependant on Format->Color , now just Document->Color .
  • We could make a way to title the page in meta comments, by grabbing it from “title” text in the page.
  • We could make a way to translate our spaces in “texmacs format” to html. Or if html does not supoprt precice enough spacing, we could make it generate a unique CSS style sheet for each html page we generate, and use that for positionign. Or if we needed to we could even make something that would auto-generate the .gif spacers for us, and auto-insert them. :)
  • We could make a system that auto-uploads a copy of the .html page to our web-server
  • We could get the system to override.... ///***what was the rest of this sentance supposed to be?

My personal todo list for this document:

make it look better

remove all the “notes to self” in the document

find how to make “comments”, which only i can see, and won't come through... like this list should be. ... use “edit source” “quote-value thing under ‘ ”

hitcounter

Or you can go to Part IV: The Hacking log

That's it for this page, but there's always more to see:

Languages of suffering-Released Articles-Upcomming Articles-Scheme code

Copyright 2004 - Corey Sweeney. All rights reserved.

In the future, the licencing may be changing. See my Future Licencing Ideas