老牌畫圖工具pic


工具有兩種,“所見即所得”和“所想即所得”。前者比如Viso/Word,后者比如pic/LaTeX。pic和Viso都是畫圖軟件,我和pic的緣分始於陳碩先生的著作——《Linux多線程服務端編程》。看完這本書我有個小小的疑問:作者用的畫圖工具是什么?后來得知是pic。其實dmr和Brian W. Kernighan所寫的那本傳世名著<The C Programming Language>中的插圖就是用的pic,Unix環境高級編程中的插圖也是用pic做出來的。pic也是貝爾實驗室開發的。 這兩本經典書籍都是用troff出版的,關於troff有興趣的讀者可以去自己挖掘。

其實某種程度上書籍的排版工具可以反映這本書的質量,由troff和LaTeX出版的幾乎都是好書。不信你看,下面列出的書籍都是troff出版的。

  1. Unix環境高級編程
  2. Unix網絡編程
  3. C程序設計語言
  4. 計算機網絡-第三版
  5. TCP/IP協議系列
  6. 程序設計實踐

這個網站上列出了用troff出版的書籍:傳送門

關於PIC其實不不需要我介紹太多,因為這個東西本身也很簡單。其實更重要的原因是Kernighan已經寫了一篇manual來教大家如何使用pic,Eric Raymond(《Unix編程藝術》的作者)也寫了一篇tutorial。我在這里給出這兩篇文章的鏈接,有興趣的同學自己去看去嘗試吧。我向您保證,2個小時絕對能看完。

大家還記得C聖經里面的這幅插圖嗎?

這個圖表就是用pic畫出的。它的pic代碼如下:

.PS
define ndblock { box wid boxwid
/2 ht boxht/2 down; box same with .t at bottom of last box; box same } boxht = .2; boxwid = .3; circlerad = .3; dx = 0.05 down; box; box; box; box ht 3*boxht "." "." "." L: box; box; box invis wid 2*boxwid "hashtab:" with .e at 1st box .w right Start: box wid .5 with .sw at 1st box.ne + (.4,.2) "..." N1: box wid .2 "n1"; D1: box wid .3 "d1" N3: box wid .4 "n3"; D3: box wid .3 "d3" box wid .4 "..." N2: box wid .5 "n2"; D2: box wid .2 "d2" arrow right from 2nd box ndblock spline -> right .2 from 3rd last box then to N1.sw + (dx,0) spline -> right .3 from 2nd last box then to D1.sw + (dx,0) arrow right from last box ndblock spline -> right .2 from 3rd last box to N2.sw-(dx,.2) to N2.sw+(dx,0) spline -> right .3 from 2nd last box to D2.sw-(dx,.2) to D2.sw+(dx,0) arrow right 2*linewid from L ndblock spline -> right .2 from 3rd last box to N3.sw + (dx,0) spline -> right .3 from 2nd last box to D3.sw + (dx,0) circlerad = .3 circle invis "ndblock" at last box.e + (1.2,.2) arrow dashed from last circle.w to last box chop 0 chop .3 box invis wid 2*boxwid "ndtable:" with .e at Start.w
.PE

編譯這個程序的步驟也很簡單

pic hashtab.pic | groff | ps2eps > hashtab.eps
epstopdf hashtab.eps

如此就生成了pdf,再把pdf轉成圖片就OK了。

請確定pic,groff,pstoeps,epstopdf已經安裝。沒有的話請自行安裝。groff是troff的變種,其他的都是LaTeX的套件。

Manual By Kernighan

Tutorial By Raymond


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM