PDF verssion of D manuals

BCS BCS at pathlink.com
Thu Dec 14 16:39:54 PST 2006


Walter Bright wrote:
> BCS wrote:
> 
>> Here is the first attack
> 
> 
> It's a good start. If you can write up the roadblocks you're 
> encountering, I can try and figure out a way to deal with them.


The problem for tables is that TeX defines tables sizes with a syntax 
like this

\begin{table}[llll]
	% a table with 4 col.
	....
\end{table}

the string that needs to be inserted into the template is the sequence 
of "l", for which there needs to be one for each col. Some sort of 
translation from "4" to "llll" is needed.

---

My first thought on how to do this is to to have a few special case 
macros that are implemented inside the compiler. For instance the "4" -> 
"llll" mapping would be easy to do in D:

"$(REPEAT_STRING l 4)" ==> repeat_string(["l", "4"]) ==> "llll"

char[] repeat_string(char[][] args)
{
	int l = args[0].length;
	int c = atoi(args[1]);
	char[] ret = new char[l*c];
	for(int i=0; i<c; i++)
		ret[i*l..(i+1)*l] = args[0];
	return ret;
}

-------

Another problem that comes up is the need to escape special character 
sequences. Some sort of sed like rule that would be applied to all raw 
text from the input file would be quite adequate.

source.d:
	$(BF hello_world $(SUB earth))

tex.ddoc:
	SUB=_{$0}
	BF={\bf $0}
	s/_/\_/

output.tex:
	{\bf hello\_world _{earth}}


-------

Another problem that showed up (cosmetic in this case) was that in some 
cases the text inside of a macro ended in a \n and caused things to look 
something like this:

  foo(); {\color{green} // comment1
} bar(); {\color{green} // comment2
}

rather than the preferred:

  foo(); {\color{green} // comment1}
  bar(); {\color{green} // comment2}


It would be nice to be able to isolate the end of the string if it is a 
newline. An off-the-cuff solution would be to have "$-" or some such be 
  any and all trailing newlines. Then something like this could be used:

COMMENT=$(GREEN $0)$-

However this would require that either those newlines be striped from $0 
when $- is used, or that a form of $0 be created that always does the 
stripping (maybe $-0)



More information about the Digitalmars-d-announce mailing list