Integrating TeX and PDF seamlessly in pdfTeX
CC Attribution - NoDerivatives 2.0 UK: England & Wales:
You are free to use, copy, distribute and transmit the work or content in unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
Doumont, Jean-Luc
In its ability to generate graphical elements, TeX is basicallylimited to horizontal and vertical black rules. Extended versions such as pdfTeX add color options and, especially, the possibilityto draw more freely on the page by inserting raw code (PDF code in thecase of pdfTeX). Still, these two coding environmentsDash TeX andPDFDash are too often regarded as disjoint. It would be nice tointegrate them seamlessly, for example, to use in PDF code a color ora dimension assigned or calculated in TeX. This presentation pointsout the challenges of such a consistent and transparent TeX–PDFintegration, proposes a set of solutions, and illustrates how thesesolutions help create graphs flexibly or design pages consistently ona grid.
 All right. Now, the year is 1987. And I'm a student doing my engineering thesis at CERN in Geneva. And I madly fall in love with a pretty little thing called MAC. And I'm the faithful type, as many of you are. You can see I'm still with the MAC at the moment. Now, one year later, I'm a PhD student at Stanford, and I fall in love all over again with a local beauty called the tech, which I'm using with one of the best environments that ever existed for tech, textures on the Macintosh. Now, that did not do everything I wanted to do, thank goodness for specials, and for the fact that textures was allowing post-cripts. So I looked into post-cript, I bought the post-cript language reference manual, and boy, that was love at first sight all over again. I'm a reverse-polish notation kind of guy, as was just reminded by Pavnit. I do my page layouts based on coordinate systems, so post-crypton and I were meant for one another. And with my own sets of simple, lean, and mean plain tech macros, I felt I was invincible. So I thought it was a slight drawback if I would type set a graph. Well, what I would see on the screen of my Mac would be this. Just the tech version. Can you see the lines here and here? Well, near the good eye, because that was the post-crypt part, and that was, of course, not so nice at the time. Sure enough, PDF came along just a little later, so I could take my post-crypt file, distill it, and then open a PDF file, and there I could see the graph, which was good, but not nearly fast enough, because visual design is a lot of trial and error, so much nicer if it goes faster. So I was hoping that Steve Jobs, may he rest in peace, would bring display post-crypt to the Mac the way he did to the next machines, but nope, instead of that he pushed Mac OS X, which the guys at Blue Sky Software doing textures did not support. Worse, he went to Intel processors, and, well, that would not run the classic environment that I needed to run my legacy copy of textures, so one day, eventually, my risk machine died of old age, and my life shattered. I had to be invincible in a different way by being reborn from my ashes, and I turned to TechShop and PDF Tech. With a lot of promise, right? It would allow me to see the PDF at once, almost instantly good for visual design. Since I'm, as many of you know, since I'm a control freak, it also allowed me to fine-tune what was going to be the final product anyway, a PDF file, but yes, there was also a slight drawback with it. Now, you can tell me, what's the fundamental difference between post-crypt and PDF? Programming language and not. I used to do a lot of calculations in post-crypt. I used to do programming in post-crypt. I couldn't do that in PDF. Example, one of the graphs that I wanted to do was this. Now, that's dead easy to do in post-crypt. In PDF, you have to describe every one of those little arcs here with cube-explines. And so you would spend a lot of time drawing the circle. That's not what I wanted to do. I wanted to spend a lot of time on page design, for example, ensuring that this would align nicely with the paragraph above and the paragraph below. So it's been a rough ride, and therefore I wanted to share with you how I eventually got over those obstacles and integrated tech and PDF. Hopefully you can learn useful lessons from that experience. And I would say the challenges were in three categories, which I would symbolize with the names, lines, colors, and shapes. Lines have got everything to do with dimension. So imagine you want to draw a line in tech. You can draw it horizontally. Suppose you want it to be seven points thick and 84 points long. Well, in the horizontal mode, you can just have this line here. Of course, it will work. What I wanted to do is draw lines in PDF, all possible directions. But if I would draw it horizontally, it had to be exactly the same as this one. So my dream was a little PDF environment, simple, in which I could say, for those of you who don't speak PDF, seven set the line width, move to zero zero, line to 84 zero, and stroke it, it had to be exactly the same. More than that, I wanted to specify the line width somewhere else. In a new dimension, I set it to seven points, and I can use that in tech and hopefully in PDF. Automatically, it would use whatever line width is currently defined. So if I change the line width at the top, I say 14 points, everywhere it changes automatically. Now, why do I want to do that? Well, probably it was just reminding you about my book, this one here, where I do a lot of graphs. You can have a look if you want. And so one thing that we did is design all the graphs with parameters, and at the end, we went on the offset print presses. We did a test with several line thicknesses in gray ink. We decided, well, this one is the one we want, and we wanted to change one parameter in one place and have everything be changed again. More still, designing pages on grid was my talk last year. Well, we wanted it to go beyond just the thickness and draw things on the square grid. So I redefined the picker to be whatever, in my case, usually 14 points. And then I can not only define the line width harmonized with the size of the square here, but I can also use the square as a unit and say the length has got to be six squares long in tech and in PDF. So instead of having a PDFPT environment for points, I have a PDFPC environment for my redefined picker there. How do you do that? Well, two things. First thing you have to learn is extract values from dimensions in tech. And you know, if you do the line width, you get seven points. Now, you don't want the P and the T in PDF code, you just want the seven to have to get rid of that. The only trick you need to know if you've never done that is this is not cut code 11 for letters. It's cut code 12. So there's just a little trick you have to know. You change the P and the T to cut code 12 and then you define a simple macro that will take something with PT and return to something without the PT. And so you can put that instruction in front of the line width, but yes, you have to expand it first so you get what you want. With that, you're ready to do the PDFPT environment. PDFLiteral is the one you get from PDFTech. You put little Q, big Q to keep the changes local. You do exactly what we said a moment ago. There was a space in there. You have to be careful with that in PDF. You set the line width and then you set the code, like 00 move to 840 line to. That will work, but it will give inaccurate results. And one has an idea why? Points are different. Tech uses 72.27 points to the inch. PDF uses 72 points to the inch. Now, that's fortunately also easy to solve. You just do a change of coordinates. Now, that's the dreaded concatenate matrix in PDF. So this is to say for now that you just need to put the scaling factor there with the rest being zero and that magical number is the ratio between 72 and 72.27. So, of course, you could say, well, actually the code that I want to put here, I would rather use the PostScript points, what Tech calls the big points. In that case, I can really find that to be PDF big points like this. I can get rid of the scaling, right? Well, except that then the line width is wrong. So what you have to do is scale the line width only, not the rest. I used to do that easily in PostScript with some code here. You can't do that in PDF, but what you can do is do it in Tech. So let's have a big group and then group to keep that local. Multiply the line width by 72.27 divided by 72 and then the rest can stay the same. That's a second one. Well, you want a third one with the redefined picker. Well, the only thing you need to take care about, again, is change of coordinate systems. Now you put 14 because I define my picker in fact as 14 big points. So it goes straight. This magical number there is 72 to 72.27 divided by 14. And at this point you could say, oh, why don't you do it automatically? Why don't you extract the value 14 from there? Put it here. That's easy to do. Now this one is a little trickier because this redefined picker need not be an integer, right? It could be 14.5 big points. So I decided to draw the line there and just do this part by hand because I had never changed that size anyway. I have one grid, maximum two for the document. So to generalize it, here's an environment in which you give the scaling factor, which you put here, what I call the unscaling factor, which you use there, including the 72.27 game. And then you just put the code there. So the three we had before, we redefined in this general frame with each time the scaling and the unscaling for the points, for the big points, and for my redefined picker to 14 big points in this case. And that gives us an excellent start. What's next? Well, you may want to have the lines in color, right? So what you could do is define some CMYK macro. You can set colors in there. And then you can define red as being 100% magenta, 100% yellow. That's got nothing to do with PDF tech. If you put that in front of what we had before, it will work in both cases. But perhaps what you would like to do is specify a color inside the literal PDF, for example, because one piece will be red, one piece will be yellow, one piece will be orange. And again, you want to be able to redefine the red at any time and have all the reds change everywhere. So the only solution for that, the simple solution, fortunately, is keep track of whether you are in PDF or in tech. Define an if PDF literal flag. And in the definition we had before, the only thing you add is you set it to true inside the group. And then you can define your color, push intermediate macro by saying, if I'm in PDF, I just dump it. If I'm not in PDF, then I have to do those things that PDF tech tells you to do and teaches you to do to set the color. And now CMYK, you push the color and here I set the color both for the stroke and for the fill. If you want to get fancy and set a different color for the stroke and for the fill, you can, of course, extend this. That will work so I can do everything that I did before and I would like to extend that to line thickness. Set the line in some, the line thickness in some way. So if I define a medium line thickness to be seven, I want to use it in front of that. I want to use it in front of that. That will work. Will it work inside PDF literal? That's a little trickier because you need to do calculations in tech. If you dump the calculations in PDF, they will not take place in tech. So the solution in this point is to say, well, we need to be able to get in and get out of PDF. So we need to split in a sense the environment we had before, have a PDF draw and an end PDF draw. We memorize the scaling factor and the unscaling factor for later. The rest is as usual. The definitions here are as usual. And now we can get in and out. You start the environment there, you stop it there, you put the length of the line in PDF, you change the thickness, and then you stroke at that point. So you have to make sure you take care of that in the line with set variable. You set it to the value of course. If it's PDF, then you need to do the scaling and spit it out in the code. If it's tech, you don't need to do anything else. So this in and out of PDF was also a solution to many problems there. The only thing we were not careful enough with, previous slide, is look at this. We have PDF literal here, but we just said here PDF is true or false. We need also to say here PDF literal becomes true or false because we might have a color specification there, right? We might want to say here red. We want to say here PDF is more than just PDF is PDF literal. So you can have a little utility that's just PDF literal before except that you set the flag to true and that will solve it for now. So we can get to the fun stuff. What's the fun stuff? The fun stuff is shapes. Example, I want to do a graph as catapult this time. I want circles. I want to be able to define circles somehow than a medium dot to be circle with a size 1.5 and in some place in the draw environment still to be defined. I would spit out the data there. Now I told you no primitive in PDF to do circles. You have to do that with at least four basic colors and you need that because you want to change the dimension and make sure all the sizes change. Small dot, big dot, things like that. So here is the PDF code you would need for a circle of radius 1. And it's four cubic splines and then you close the circle and you stroke it or fill it or something. Nice, easy. Because of the symmetry of the circle, the number that you see there is always the same. That's nice. But what if you want to do a circle that's not of radius 1? Well, scaling, again, we learned to do that with the first two points. We can apply that here. So here's the trick in this case. Define two dimensions and let's have a shortcut to extract the value corresponding to that dimension. And then what you do, one dimension you say that's the radius. The other dimension, that's this famous number that we saw a moment ago, multiplying the radius. And then you put those A's and those B's in the right sequence with the right side in front of it. That will give you circles. So I'm defining that and expanding that inside the macro that I called marker. And my scatterplots, macros, they know that whenever they go, they have to call marker. That will put the circle there and they can move some places else. Circles, easy. Well, what if it's only part of a circle? In particular, what if it is rotation of coordinates? That also used to be so simple in PostScript. You say rotate 30 degrees, period. You can do that in PDF. You just have to put cosine, sine, minus sine and cosine of the angle and zero, zero. Great. How the heck am I going to compute a cosine in tech? For a split second, I thought I would use a Taylor expansion in integer arithmetics, but I was not chickened out of that one and I thought we need something else. So basically what happened is I don't need this much. Occasionally, I could text 45 degrees, very occasionally vertical, even less frequent, 180 degrees on documents I will fold or something. So I just defined macros for that. And I was happy. I postponed it forever. But then what happened is my kids started learning how to read clocks, another clock in school and they needed a little help with that because they had to learn that in Dutch. And in Dutch, if it's 235, you have to say that it's five minutes after half an hour before three, which is a complicated mental gymnastics. So I wanted a simple clock macro that would draw a clock like that. And then either I would draw hands on it and ask them what's the time, or I would give them the time and they would draw their hands on it. Now how could I do that without being able to rotate freely? Well, I figured this is just six degrees, right? So let's have a macro that rotates six degrees. And let's make sure we can draw thick lines left, right, top and bottom. Long ones for hours, short ones for minutes. So basically what happens in the programming, I said, well, hour. Rotate six degrees, minutes. And so on. So I did hours, minute, minute, minute, minute, hour, minute, minute, minute, minute. And so three times that draws this and a little circle in the middle. Good. That was an easy way out until I started being tired of drawing hands on clocks by hands. So I figured I need to revise this macro and be able to say clock 234.55 and it draws this. And then with PDF Tech you can even use the random number generator. I could make a whole sheet of those for my kids and have a separate sheet with the solutions for me. So I could even look it up. Now the solution here was to say, hey, let's pretend it's a train station clock. That means the pointers go click and they move six degrees at once. So the best I could come up with in this case is just a lookup table. Here is a long list that takes this parameter from 0 to 59 and it turns the corresponding number of degrees. So that's useful for the seconds here. It's each time one of those discrete positions. I'm a quantum space kind of guy. This works also for the minutes. It almost works for the hours. You could say, well, let's multiply the hour by 12 and so by five, by five. And then you can have it, but of course then the line would show to a clock. And we want it to be somewhere in between. So in that case, instead of difficult complications, I just did two changes of coordinates. I first change it to two. Then I have a different lookup table that will map 60 minutes into this interval here. And I will move it just a little more for the minutes. And I think that's a solution for a generic macro that will do any rotation. I think you want to take 32.67 degree. I think what you want to do is take the number three and have a simple lookup table that will move in tenths of degrees. Then you take the two and you have another lookup table that moves in degrees from one to ten, from 0 to 9 maybe. Then you have one that moves in tenths of degrees and so on. You don't even need dimensions in tech for that. So I'm going to write 32.67 and have a macro that will gobble the digits one by one and do the necessary stuff. I didn't do that yet. Why? Because my concern is elsewhere. Arrowheads. Where the macros we defined so far? Easy. You just draw a little triangle. You paint it. You stroke it. Works. But what if you have a sloped line? Or you could say, well, you just go there after drawing the line. You rotate and you draw the same arrowhead. Except you don't even have the angle now. You have the delta x, the delta y. If you make the ratio between the two, you have the tangents of the angle. So in addition to calculating signs and cosines, you have to calculate in tech and arc tangents, which I didn't do either. I figured there must be a better way. But what's the problem with a lookup table in this case? Well, imagine that this goes closer and closer to vertical. Tension goes to infinity. Do you want to lookup table that goes all the way to infinity? Not very practical. Solution? Symmetry. You do it up to 45 degrees. And beyond that, you take the cotangents and you figure things out. That's just for one of the quadrants. For the other three quadrants, then you would just play with plus signs and minus signs. So I thought for a second, because of this conference, I'll do this the Boris way. And just tell you, please do that by tomorrow as a homework. But I was energized after the banquet last night, and so this is a midnight hack to do exactly that. And as you can see, it actually works. And it's not that long. No, I'm not showing you the lookup table. And if Didier were still here, he would have lots of things to say about the way I display this, but it fits on one slide. You just see if x is negative, and then you worry about the signs and making it positive. You do the same with y. You worry whether x is smaller than y or vice versa. And then you do a division, which I multiply by 10 to go in my lookup table from 0 to 100 instead of 100. And then the only thing you have to do is make sure that if it's inverted and you have a cotangent, then you go get the sign from the lookup table and you put that in the cosine definition and vice versa. If it's not the case, it's straightforward. And then here's just your pdf code. Draw the line, move to the end, do your little rotation, and then draw an arrow head. Of course, this you could describe as a tec-macro and have dimensions for the head of your arrow and everything. All right. So we have learned you can do a lot if you can extract numbers from units in tec, if you can play with coordinates, if you can get in and out of pdf and of tec and the master replaces, and if you can be creative and perhaps discretize what is there, the way we did with lookup tables for integrals in the good old days before we compute this, we look up and do interpolations and such. Conclusion and perspectives out of this, well, my major conclusion for myself, is I feel confident now that I will be able to do in pdf everything that I used to do in PostScript. And that is going to be put to the test very soon because my book in, before the year is over, my book is due for a third print round and the first two print jobs were done with the PostScript version. Now I have to go to pdf. I have brought enough copies with me if you want to buy one and get the discount as usual, but soon I will be out of books I have to go and rip in that. That's great. The best test. Now I say it's possible. Some things are going to remain difficult. Example, not in the book, but in the lecture notes I have for a course I gave on statistical thinking. Guess what? I do a lot of normal distributions. In PostScript, two lines of code. I would define the Gauss curve and just say to PostScript, please plot that from 0 to 16 in steps of 0.05. Then in function data and end data, there was no necessary programming to do that. So simple. What do you have to do now in pdf? Give it all the values. Now it gives me finer control, but it clutters my tech file. That's the drawback. How do you do this? Any way you want. I bet some of you who are into Microsoft products would do this in Excel. Fine, it works. Myself I like to do that just with PHP. A few lines of PHP code. I put that in a browser. If I'm careful with the format, what comes in the browser I can copy and paste directly in my tech file works well. So the very last thing we need to worry about was our challenge from the beginning. How about this pie chart now? How do you do all the basic curves for all of these pieces? Well, it's not forbidden to have some PostgreP help. So the way I did this is I used my old PostgreP code, very short. I put that in an almost as short encapsulated PostgreP file. I opened that in acrobat on preview on the Mac and I get a PDF file automatically. Now what do you do with a PDF file? Well, I bet most of you would keep it on the hard drive and insert it in the right place. You can do that. Well, that's not so good enough for a control freak such as myself. So what I do is say, oh, it's in PDF now. Let's go inside and see how they do it. And so I go steal the PDF code inside that distilled file. Then I put that PDF code in my tech PDF programming here and I can generate this from within the file. And I don't have those extra little files around on my hard drive. So yes, it is possible with some help from a number of tools around it. So the year is now 2011 and I really hope that for me and PDF Tech and for you and PDF Tech, it's going to be happily ever after. Okay, there's time for lots of questions. And my first question, I'm going to ask the question someone else is going to ask. You showed that pie chart. You said, oh, I just snip it out of the PDF from the preview. Just what does that look like? Do you have that ready to show us? Oh, it looks like inside. Actually, I've been learning from Don Knuth himself to tell little white lies every so often. So what's the problem with the PDF? It's compression. It's flat compressed. So here's the trick. It's no secret. What I actually do is, since I did not find a simple way to uncompress it, if you have a way, I mean share it with me, a simple way, not a complicated way, not a unique way, but a simple way. But the other thing that I found is I re-exported as a post-crypt. And now it's not the same post-crypt that it used to be because it's a converted post-crypt. Now that's not PDF, but it's close enough. And then I have to go and do by hand very little conversions. L, I need to become L and small things. And then I've got it. But yes, it's admittedly not totally as clean as I made it sound. But please talk to me during the break if you have a deflator that I can easily use on my Mac. I'll be listening, but we can do that. Okay, we can do that. Just a quick comment about trigonometry. Actually, in Lattec there is a package which actually works, at least the offer David Carroll said, it works in plain tech, which does exactly calculation of sine, cosine and 10, using Taylor expansions in tech. So just look at trig.sty and it has, the code is not very fair and it works without lookup tables just using Taylor expansion. Even for real numbers? Yes, yes, even for, yes. It's very good code. I really love it. I'm using most of the time PS tricks. Am I missing something from PS tricks and you are getting something more? Well, if you still want to do postcripts, it is possible. You can use PS tricks, but then, or whatever, I have experimented in my own little world. If you stay in postcript and away from the source to the eventual thing you see on the screen is longer, and I decided it was too slow for me. Now remember, I was coming from textures on the Macintosh and it was even called lightning textures. I could write code in the source file and it will type set automatically in real time in the other window. And so I wanted something fast. There was one reason. The other reason is that there were a number of things in PDF tech, separately from what I've shown you here, separately from graphics that were of interest to me, including the possibility to stretch a little bit some lines. That was nice. I'm not sure it's still important now, but at the time I made the decision it was something. So that's the way I did. But if you want to stay postcript, as far as I know, it is possible. It is possible. Other questions? So you're going to look up table also? Yes. Okay, that's good to know. That's good to know. So I'm going to investigate the calculation way, but when I started with my look up table I thought, is this even a good idea? And it's nice to know that you go that way. Okay. Yeah. All right. Well, I think the thing I need to do at this point in my life is get into integer arithmetics and understand the limitations on the size of variables in second, make sure I get my precision, my accuracy right in there, which I haven't had time to do yet because I'm... Yeah. Yeah. Well, let's be in touch. Yeah, thank you. Okay. Anybody else? It looks like there's no more questions. Kevin may have one or another. I believe it is. Thank you very much, Jonathan. Firstly, just a comment. If you haven't seen the book and if you have books to say, it's the most beautiful book that Jonathan has produced, so I would recommend you, they are available to say, if you want to buy them, I have one. And it just... I haven't read it, but I just sit down. Yes. I think you're almost certified as mad if I make this. Absolutely. More than him. Stay away from me later. Look at the book. Every paragraph ends flush right. And I think... Have you rewritten those to be rewritten the text to be... Yes, absolutely. It's not stretching anything. It's written in the page layout. So... If a single paragraph is flush left and flush right. If it was just that, I mean, the line breaks are usually at commas and periods and everything, so that's total madness. But guess why I ended up publishing it myself? That explains it. So thank you very much. Just a couple of very quick announcements. If you want to go to the airport early today, if you need a cab, please tell someone at this e-brake in the area there so we can arrange it for you. And quickly, secondly, they say, better late than never, we have some badges for you. No. Yes. We thought, yeah, so in the coffee area, there are some badges. So if you want to see me, please pull out.
 All right.  Now, the year is 1987.  And I'm a student doing my engineering thesis at CERN in Geneva.  And I madly fall in love with a pretty little thing called MAC.  And I'm the faithful type, as many of you are.  You can see I'm still with the MAC at the moment.  Now, one year later, I'm a PhD student at Stanford,  and I fall in love all over again with a local beauty called the tech,  which I'm using with one of the best environments that ever existed for tech,  textures on the Macintosh.  Now, that did not do everything I wanted to do, thank goodness for specials,  and for the fact that textures was allowing post-cripts.  So I looked into post-cript, I bought the post-cript language reference manual,  and boy, that was love at first sight all over again.  I'm a reverse-polish notation kind of guy, as was just reminded by Pavnit.  I do my page layouts based on coordinate systems,  so post-crypton and I were meant for one another.  And with my own sets of simple, lean, and mean plain tech macros,  I felt I was invincible.  So I thought it was a slight drawback if I would type set a graph.  Well, what I would see on the screen of my Mac would be this.  Just the tech version.  Can you see the lines here and here?  Well, near the good eye, because that was the post-crypt part,  and that was, of course, not so nice at the time.  Sure enough, PDF came along just a little later,  so I could take my post-crypt file, distill it,  and then open a PDF file, and there I could see the graph,  which was good, but not nearly fast enough,  because visual design is a lot of trial and error,  so much nicer if it goes faster.  So I was hoping that Steve Jobs, may he rest in peace,  would bring display post-crypt to the Mac the way he did to the next machines,  but nope, instead of that he pushed Mac OS X,  which the guys at Blue Sky Software doing textures did not support.  Worse, he went to Intel processors,  and, well, that would not run the classic environment that I needed  to run my legacy copy of textures,  so one day, eventually, my risk machine died of old age,  and my life shattered.  I had to be invincible in a different way  by being reborn from my ashes,  and I turned to TechShop and PDF Tech.  With a lot of promise, right?  It would allow me to see the PDF at once,  almost instantly good for visual design.  Since I'm, as many of you know, since I'm a control freak,  it also allowed me to fine-tune what was going to be the final product anyway,  a PDF file, but yes, there was also a slight drawback with it.  Now, you can tell me, what's the fundamental difference between post-crypt and PDF?  Programming language and not.  I used to do a lot of calculations in post-crypt.  I used to do programming in post-crypt.  I couldn't do that in PDF.  Example, one of the graphs that I wanted to do was this.  Now, that's dead easy to do in post-crypt.  In PDF, you have to describe every one of those little arcs here with cube-explines.  And so you would spend a lot of time drawing the circle.  That's not what I wanted to do.  I wanted to spend a lot of time on page design,  for example, ensuring that this would align nicely with the paragraph above and the paragraph below.  So it's been a rough ride, and therefore I wanted to share with you  how I eventually got over those obstacles and integrated tech and PDF.  Hopefully you can learn useful lessons from that experience.  And I would say the challenges were in three categories,  which I would symbolize with the names, lines, colors, and shapes.  Lines have got everything to do with dimension.  So imagine you want to draw a line in tech.  You can draw it horizontally.  Suppose you want it to be seven points thick and 84 points long.  Well, in the horizontal mode, you can just have this line here.  Of course, it will work.  What I wanted to do is draw lines in PDF, all possible directions.  But if I would draw it horizontally, it had to be exactly the same as this one.  So my dream was a little PDF environment, simple,  in which I could say, for those of you who don't speak PDF,  seven set the line width, move to zero zero, line to 84 zero,  and stroke it, it had to be exactly the same.  More than that, I wanted to specify the line width somewhere else.  In a new dimension, I set it to seven points,  and I can use that in tech and hopefully in PDF.  Automatically, it would use whatever line width is currently defined.  So if I change the line width at the top, I say 14 points,  everywhere it changes automatically.  Now, why do I want to do that?  Well, probably it was just reminding you about my book,  this one here, where I do a lot of graphs.  You can have a look if you want.  And so one thing that we did is design all the graphs with parameters,  and at the end, we went on the offset print presses.  We did a test with several line thicknesses in gray ink.  We decided, well, this one is the one we want,  and we wanted to change one parameter in one place  and have everything be changed again.  More still, designing pages on grid was my talk last year.  Well, we wanted it to go beyond just the thickness  and draw things on the square grid.  So I redefined the picker to be whatever,  in my case, usually 14 points.  And then I can not only define the line width harmonized  with the size of the square here,  but I can also use the square as a unit  and say the length has got to be six squares long in tech and in PDF.  So instead of having a PDFPT environment for points,  I have a PDFPC environment for my redefined picker there.  How do you do that? Well, two things.  First thing you have to learn is extract values from dimensions in tech.  And you know, if you do the line width, you get seven points.  Now, you don't want the P and the T in PDF code,  you just want the seven to have to get rid of that.  The only trick you need to know if you've never done that is  this is not cut code 11 for letters.  It's cut code 12.  So there's just a little trick you have to know.  You change the P and the T to cut code 12 and then you define a simple macro  that will take something with PT and return to something without the PT.  And so you can put that instruction in front of the line width,  but yes, you have to expand it first so you get what you want.  With that, you're ready to do the PDFPT environment.  PDFLiteral is the one you get from PDFTech.  You put little Q, big Q to keep the changes local.  You do exactly what we said a moment ago.  There was a space in there.  You have to be careful with that in PDF.  You set the line width and then you set the code, like 00 move to 840 line to.  That will work, but it will give inaccurate results.  And one has an idea why?  Points are different.  Tech uses 72.27 points to the inch.  PDF uses 72 points to the inch.  Now, that's fortunately also easy to solve.  You just do a change of coordinates.  Now, that's the dreaded concatenate matrix in PDF.  So this is to say for now that you just need to put the scaling factor there  with the rest being zero and that magical number is the ratio between 72 and 72.27.  So, of course, you could say, well, actually the code that I want to put here,  I would rather use the PostScript points, what Tech calls the big points.  In that case, I can really find that to be PDF big points like this.  I can get rid of the scaling, right?  Well, except that then the line width is wrong.  So what you have to do is scale the line width only, not the rest.  I used to do that easily in PostScript with some code here.  You can't do that in PDF, but what you can do is do it in Tech.  So let's have a big group and then group to keep that local.  Multiply the line width by 72.27 divided by 72 and then the rest can stay the same.  That's a second one.  Well, you want a third one with the redefined picker.  Well, the only thing you need to take care about, again, is change of coordinate systems.  Now you put 14 because I define my picker in fact as 14 big points.  So it goes straight.  This magical number there is 72 to 72.27 divided by 14.  And at this point you could say, oh, why don't you do it automatically?  Why don't you extract the value 14 from there?  Put it here.  That's easy to do.  Now this one is a little trickier because this redefined picker need not be an integer, right?  It could be 14.5 big points.  So I decided to draw the line there and just do this part by hand because I had never changed that size anyway.  I have one grid, maximum two for the document.  So to generalize it, here's an environment in which you give the scaling factor, which you put here,  what I call the unscaling factor, which you use there, including the 72.27 game.  And then you just put the code there.  So the three we had before, we redefined in this general frame with each time the scaling and the unscaling  for the points, for the big points, and for my redefined picker to 14 big points in this case.  And that gives us an excellent start.  What's next?  Well, you may want to have the lines in color, right?  So what you could do is define some CMYK macro.  You can set colors in there.  And then you can define red as being 100% magenta, 100% yellow.  That's got nothing to do with PDF tech.  If you put that in front of what we had before, it will work in both cases.  But perhaps what you would like to do is specify a color inside the literal PDF, for example,  because one piece will be red, one piece will be yellow, one piece will be orange.  And again, you want to be able to redefine the red at any time and have all the reds change everywhere.  So the only solution for that, the simple solution, fortunately, is keep track of whether you are in PDF or in tech.  Define an if PDF literal flag.  And in the definition we had before, the only thing you add is you set it to true inside the group.  And then you can define your color, push intermediate macro by saying,  if I'm in PDF, I just dump it.  If I'm not in PDF, then I have to do those things that PDF tech tells you to do and teaches you to do to set the color.  And now CMYK, you push the color and here I set the color both for the stroke and for the fill.  If you want to get fancy and set a different color for the stroke and for the fill, you can, of course, extend this.  That will work so I can do everything that I did before and I would like to extend that to line thickness.  Set the line in some, the line thickness in some way.  So if I define a medium line thickness to be seven, I want to use it in front of that.  I want to use it in front of that.  That will work.  Will it work inside PDF literal?  That's a little trickier because you need to do calculations in tech.  If you dump the calculations in PDF, they will not take place in tech.  So the solution in this point is to say, well, we need to be able to get in and get out of PDF.  So we need to split in a sense the environment we had before, have a PDF draw and an end PDF draw.  We memorize the scaling factor and the unscaling factor for later.  The rest is as usual.  The definitions here are as usual.  And now we can get in and out.  You start the environment there, you stop it there, you put the length of the line in PDF, you change the thickness, and then you stroke at that point.  So you have to make sure you take care of that in the line with set variable.  You set it to the value of course.  If it's PDF, then you need to do the scaling and spit it out in the code.  If it's tech, you don't need to do anything else.  So this in and out of PDF was also a solution to many problems there.  The only thing we were not careful enough with, previous slide, is look at this.  We have PDF literal here, but we just said here PDF is true or false.  We need also to say here PDF literal becomes true or false because we might have a color specification there, right?  We might want to say here red.  We want to say here PDF is more than just PDF is PDF literal.  So you can have a little utility that's just PDF literal before except that you set the flag to true and that will solve it for now.  So we can get to the fun stuff.  What's the fun stuff?  The fun stuff is shapes.  Example, I want to do a graph as catapult this time.  I want circles.  I want to be able to define circles somehow than a medium dot to be circle with a size 1.5 and in some place in the draw environment still to be defined.  I would spit out the data there.  Now I told you no primitive in PDF to do circles.  You have to do that with at least four basic colors and you need that because you want to change the dimension and make sure all the sizes change.  Small dot, big dot, things like that.  So here is the PDF code you would need for a circle of radius 1.  And it's four cubic splines and then you close the circle and you stroke it or fill it or something.  Nice, easy.  Because of the symmetry of the circle, the number that you see there is always the same.  That's nice.  But what if you want to do a circle that's not of radius 1?  Well, scaling, again, we learned to do that with the first two points.  We can apply that here.  So here's the trick in this case.  Define two dimensions and let's have a shortcut to extract the value corresponding to that dimension.  And then what you do, one dimension you say that's the radius.  The other dimension, that's this famous number that we saw a moment ago, multiplying the radius.  And then you put those A's and those B's in the right sequence with the right side in front of it.  That will give you circles.  So I'm defining that and expanding that inside the macro that I called marker.  And my scatterplots, macros, they know that whenever they go, they have to call marker.  That will put the circle there and they can move some places else.  Circles, easy.  Well, what if it's only part of a circle?  In particular, what if it is rotation of coordinates?  That also used to be so simple in PostScript.  You say rotate 30 degrees, period.  You can do that in PDF.  You just have to put cosine, sine, minus sine and cosine of the angle and zero, zero.  Great.  How the heck am I going to compute a cosine in tech?  For a split second, I thought I would use a Taylor expansion in integer arithmetics,  but I was not chickened out of that one and I thought we need something else.  So basically what happened is I don't need this much.  Occasionally, I could text 45 degrees, very occasionally vertical, even less frequent,  180 degrees on documents I will fold or something.  So I just defined macros for that.  And I was happy.  I postponed it forever.  But then what happened is my kids started learning how to read clocks, another clock in school  and they needed a little help with that because they had to learn that in Dutch.  And in Dutch, if it's 235, you have to say that it's five minutes after half an hour before three,  which is a complicated mental gymnastics.  So I wanted a simple clock macro that would draw a clock like that.  And then either I would draw hands on it and ask them what's the time,  or I would give them the time and they would draw their hands on it.  Now how could I do that without being able to rotate freely?  Well, I figured this is just six degrees, right?  So let's have a macro that rotates six degrees.  And let's make sure we can draw thick lines left, right, top and bottom.  Long ones for hours, short ones for minutes.  So basically what happens in the programming, I said, well, hour.  Rotate six degrees, minutes.  And so on.  So I did hours, minute, minute, minute, minute, hour, minute, minute, minute, minute.  And so three times that draws this and a little circle in the middle.  Good.  That was an easy way out until I started being tired of drawing hands on clocks by hands.  So I figured I need to revise this macro and be able to say clock 234.55 and it draws this.  And then with PDF Tech you can even use the random number generator.  I could make a whole sheet of those for my kids and have a separate sheet with the solutions for me.  So I could even look it up.  Now the solution here was to say, hey, let's pretend it's a train station clock.  That means the pointers go click and they move six degrees at once.  So the best I could come up with in this case is just a lookup table.  Here is a long list that takes this parameter from 0 to 59 and it turns the corresponding number of degrees.  So that's useful for the seconds here.  It's each time one of those discrete positions.  I'm a quantum space kind of guy.  This works also for the minutes.  It almost works for the hours.  You could say, well, let's multiply the hour by 12 and so by five, by five.  And then you can have it, but of course then the line would show to a clock.  And we want it to be somewhere in between.  So in that case, instead of difficult complications, I just did two changes of coordinates.  I first change it to two.  Then I have a different lookup table that will map 60 minutes into this interval here.  And I will move it just a little more for the minutes.  And I think that's a solution for a generic macro that will do any rotation.  I think you want to take 32.67 degree.  I think what you want to do is take the number three and have a simple lookup table that will move in tenths of degrees.  Then you take the two and you have another lookup table that moves in degrees from one to ten, from 0 to 9 maybe.  Then you have one that moves in tenths of degrees and so on.  You don't even need dimensions in tech for that.  So I'm going to write 32.67 and have a macro that will gobble the digits one by one and do the necessary stuff.  I didn't do that yet.  Why?  Because my concern is elsewhere.  Arrowheads.  Where the macros we defined so far?  Easy.  You just draw a little triangle.  You paint it.  You stroke it.  Works.  But what if you have a sloped line?  Or you could say, well, you just go there after drawing the line.  You rotate and you draw the same arrowhead.  Except you don't even have the angle now.  You have the delta x, the delta y.  If you make the ratio between the two, you have the tangents of the angle.  So in addition to calculating signs and cosines, you have to calculate in tech and arc tangents, which I didn't do either.  I figured there must be a better way.  But what's the problem with a lookup table in this case?  Well, imagine that this goes closer and closer to vertical.  Tension goes to infinity.  Do you want to lookup table that goes all the way to infinity?  Not very practical.  Solution?  Symmetry.  You do it up to 45 degrees.  And beyond that, you take the cotangents and you figure things out.  That's just for one of the quadrants.  For the other three quadrants, then you would just play with plus signs and minus signs.  So I thought for a second, because of this conference, I'll do this the Boris way.  And just tell you, please do that by tomorrow as a homework.  But I was energized after the banquet last night, and so this is a midnight hack to do exactly that.  And as you can see, it actually works.  And it's not that long.  No, I'm not showing you the lookup table.  And if Didier were still here, he would have lots of things to say about the way I display this, but it fits on one slide.  You just see if x is negative, and then you worry about the signs and making it positive.  You do the same with y.  You worry whether x is smaller than y or vice versa.  And then you do a division, which I multiply by 10 to go in my lookup table from 0 to 100 instead of 100.  And then the only thing you have to do is make sure that if it's inverted and you have a cotangent,  then you go get the sign from the lookup table and you put that in the cosine definition and vice versa.  If it's not the case, it's straightforward.  And then here's just your pdf code.  Draw the line, move to the end, do your little rotation, and then draw an arrow head.  Of course, this you could describe as a tec-macro and have dimensions for the head of your arrow and everything.  All right.  So we have learned you can do a lot if you can extract numbers from units in tec,  if you can play with coordinates, if you can get in and out of pdf and of tec and the master replaces,  and if you can be creative and perhaps discretize what is there,  the way we did with lookup tables for integrals in the good old days before we compute this,  we look up and do interpolations and such.  Conclusion and perspectives out of this, well, my major conclusion for myself,  is I feel confident now that I will be able to do in pdf everything that I used to do in PostScript.  And that is going to be put to the test very soon because my book in, before the year is over,  my book is due for a third print round and the first two print jobs were done with the PostScript version.  Now I have to go to pdf.  I have brought enough copies with me if you want to buy one and get the discount as usual,  but soon I will be out of books I have to go and rip in that.  That's great. The best test.  Now I say it's possible.  Some things are going to remain difficult.  Example, not in the book, but in the lecture notes I have for a course I gave on statistical thinking.  Guess what? I do a lot of normal distributions.  In PostScript, two lines of code.  I would define the Gauss curve and just say to PostScript, please plot that from 0 to 16 in steps of 0.05.  Then in function data and end data, there was no necessary programming to do that.  So simple. What do you have to do now in pdf? Give it all the values.  Now it gives me finer control, but it clutters my tech file. That's the drawback.  How do you do this? Any way you want.  I bet some of you who are into Microsoft products would do this in Excel.  Fine, it works.  Myself I like to do that just with PHP.  A few lines of PHP code.  I put that in a browser. If I'm careful with the format,  what comes in the browser I can copy and paste directly in my tech file works well.  So the very last thing we need to worry about was our challenge from the beginning.  How about this pie chart now?  How do you do all the basic curves for all of these pieces?  Well, it's not forbidden to have some PostgreP help.  So the way I did this is I used my old PostgreP code, very short.  I put that in an almost as short encapsulated PostgreP file.  I opened that in acrobat on preview on the Mac and I get a PDF file automatically.  Now what do you do with a PDF file?  Well, I bet most of you would keep it on the hard drive and insert it in the right place.  You can do that. Well, that's not so good enough for a control freak such as myself.  So what I do is say, oh, it's in PDF now.  Let's go inside and see how they do it.  And so I go steal the PDF code inside that distilled file.  Then I put that PDF code in my tech PDF programming here and I can generate this from within the file.  And I don't have those extra little files around on my hard drive.  So yes, it is possible with some help from a number of tools around it.  So the year is now 2011 and I really hope that for me and PDF Tech and for you and PDF Tech,  it's going to be happily ever after.  Okay, there's time for lots of questions.  And my first question, I'm going to ask the question someone else is going to ask.  You showed that pie chart. You said, oh, I just snip it out of the PDF from the preview.  Just what does that look like? Do you have that ready to show us?  Oh, it looks like inside.  Actually, I've been learning from Don Knuth himself to tell little white lies every so often.  So what's the problem with the PDF? It's compression.  It's flat compressed. So here's the trick. It's no secret.  What I actually do is, since I did not find a simple way to uncompress it,  if you have a way, I mean share it with me, a simple way, not a complicated way, not a unique way,  but a simple way. But the other thing that I found is I re-exported as a post-crypt.  And now it's not the same post-crypt that it used to be because it's a converted post-crypt.  Now that's not PDF, but it's close enough.  And then I have to go and do by hand very little conversions.  L, I need to become L and small things. And then I've got it.  But yes, it's admittedly not totally as clean as I made it sound.  But please talk to me during the break if you have a deflator that I can easily use on my Mac.  I'll be listening, but we can do that.  Okay, we can do that.  Just a quick comment about trigonometry.  Actually, in Lattec there is a package which actually works, at least the offer David Carroll said,  it works in plain tech, which does exactly calculation of sine, cosine and 10,  using Taylor expansions in tech.  So just look at trig.sty and it has, the code is not very fair and it works without lookup tables just using Taylor expansion.  Even for real numbers?  Yes, yes, even for, yes.  It's very good code. I really love it.  I'm using most of the time PS tricks.  Am I missing something from PS tricks and you are getting something more?  Well, if you still want to do postcripts, it is possible.  You can use PS tricks, but then, or whatever, I have experimented in my own little world.  If you stay in postcript and away from the source to the eventual thing you see on the screen is longer,  and I decided it was too slow for me.  Now remember, I was coming from textures on the Macintosh and it was even called lightning textures.  I could write code in the source file and it will type set automatically in real time in the other window.  And so I wanted something fast.  There was one reason.  The other reason is that there were a number of things in PDF tech, separately from what I've shown you here,  separately from graphics that were of interest to me, including the possibility to stretch a little bit some lines.  That was nice.  I'm not sure it's still important now, but at the time I made the decision it was something.  So that's the way I did.  But if you want to stay postcript, as far as I know, it is possible.  It is possible.  Other questions?  So you're going to look up table also?  Yes.  Okay, that's good to know.  That's good to know.  So I'm going to investigate the calculation way, but when I started with my look up table I thought,  is this even a good idea?  And it's nice to know that you go that way.  Okay.  Yeah.  All right.  Well, I think the thing I need to do at this point in my life is get into integer arithmetics and understand the limitations  on the size of variables in second, make sure I get my precision, my accuracy right in there,  which I haven't had time to do yet because I'm...  Yeah.  Yeah.  Well, let's be in touch.  Yeah, thank you.  Okay.  Anybody else?  It looks like there's no more questions.  Kevin may have one or another.  I believe it is.  Thank you very much, Jonathan.  Firstly, just a comment.  If you haven't seen the book and if you have books to say, it's the most beautiful book that Jonathan has produced,  so I would recommend you, they are available to say, if you want to buy them, I have one.  And it just...  I haven't read it, but I just sit down.  Yes.  I think you're almost certified as mad if I make this.  Absolutely.  More than him.  Stay away from me later.  Look at the book.  Every paragraph ends flush right.  And I think...  Have you rewritten those to be rewritten the text to be...  Yes, absolutely.  It's not stretching anything.  It's written in the page layout.  So...  If a single paragraph is flush left and flush right.  If it was just that, I mean, the line breaks are usually at commas and periods and everything,  so that's total madness.  But guess why I ended up publishing it myself?  That explains it.  So thank you very much.  Just a couple of very quick announcements.  If you want to go to the airport early today, if you need a cab, please tell someone at  this e-brake in the area there so we can arrange it for you.  And quickly, secondly, they say, better late than never, we have some badges for you.  No.  Yes.  We thought, yeah, so in the coffee area, there are some badges.  So if you want to see me, please pull out.
Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_0_167.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_168_1475.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_1476_5015.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_5016_6359.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_6360_8279.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_8280_8495.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_8496_10619.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_10620_16139.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_16140_17111.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_17112_24395.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_24396_32783.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_32784_33419.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_33420_33971.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_33972_34343.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_34344_36095.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_36096_38075.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_38076_38171.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_38172_38315.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_38316_38591.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_38592_38711.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_38712_40367.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_40368_40415.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_40416_41891.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_41892_43535.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_43536_44159.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_44160_47003.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_47004_47591.png Integrating_TeX_and_PDF_seamlessly_in_pdfTeX_47592_48965.png