用Git+Sphinx记笔记?

接前面TeX、LaTeX、TeXLive 小结,练习使用Sphinx写点东西:

效果

图1:


图2:


git

Google code 提供Git

只是不清楚什么原因,无论 push 还是 pull 总是失败。(伟大的墙在发挥作用?)

* About to connect() to code.google.com port 443 (#0)
*   Trying 72.14.203.102... * Connection timed out
* Failed connect to code.google.com:443; Connection timed out
* Closing connection #0
* About to connect() to code.google.com port 443 (#0)
*   Trying 72.14.203.102... * Connection reset by peer
* Failed connect to code.google.com:443; Connection reset by peer
* Closing connection #0
error: Failed connect to code.google.com:443; Connection reset by peer while accessing https://code.google.com/p/debao-qt-blogs/info/refs

那就使用 gitorious 了。

sphinx

TeX、LaTeX、TeXLive 小结一文中,是直接修改Sphinx的latex生成器来支持中文的,不过稍后发现,设置项目的配置文件就可以实现了:

  • conf.py

latex_elements = {
        'babel':'',
        'fontpkg':'',
        'inputenc':'',
        'fontenc':'',
        'utf8extra':''
}

latex_docclass = {
        'howto':'ctexart',
        'manual':'ctexrep'
}

只需要添加这两项即可。

尽管如此,Sphinx的latex生成器还是很不成熟,在当前稳定版Sphinx 1.0.8 尚不支持表格的rowspan和colspan。源码仓库中的Sphinx 1.1 开始支持表格的这两个属性,不过rowspan有bug(无法正常工作)。

简单改动一下,凑活一下:

birkenfeld-sphinx-0dc8c4da3ef5

--- a/latex.py
+++ b/latex.py
@@ -730,19 +730,29 @@ class LaTeXTranslator(nodes.NodeVisitor):
     def visit_row(self, node):
         self.table.col = 0
     def depart_row(self, node):
+        for col in range(self.table.col, self.table.colcount):
+            self.body.append(' & ')
         if self.previous_spanning_row == 1:
-            self.previous_spanning_row = 0
+            #self.previous_spanning_row = 0
             self.body.append('\\\\\n')
         else:
             self.body.append('\\\\\\hline\n')
         self.table.rowcount += 1
 
     def visit_entry(self, node):
-        if self.remember_multirow.get(0, 0) > 1:
-            self.body.append(' & ')
+        print "visit_entry:", self.table.rowcount, self.table.col, self.table.c
+        for col in range(self.table.col, self.table.colcount):
+            if self.remember_multirow.get(col, 0) > 1:
+                self.remember_multirow[col] -= 1
+                if self.remember_multirow[col] == 1:
+                    self.previous_spanning_row = 0
+                if self.table.col > 0:
+                    self.body.append(' & ')
+            else:
+                self.table.col = col
+                break
         if self.table.col > 0:
             self.body.append(' & ')
-        self.table.col += 1
         self.context.append('')
         if 'morerows' in node:
             self.body.append(' \multirow{')
@@ -751,10 +761,11 @@ class LaTeXTranslator(nodes.NodeVisitor):
             self.body.append('}{*}{')
             self.context.append('}')
             self.remember_multirow[self.table.col] = node.get('morerows') + 1
+            self.previous_spanning_row = 1
         if 'morecols' in node:
             self.body.append(' \multicolumn{')
             self.body.append(str(node.get('morecols') + 1))
-            if self.table.col == 1:
+            if self.table.col == 0:
                 self.body.append('}{|l|}{')
             else:
                 self.body.append('}{l|}{')
@@ -762,9 +773,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
         if isinstance(node.parent.parent, nodes.thead):
             self.body.append('\\textbf{')
             self.context.append('}')
-        if self.remember_multirow.get(self.table.col + 1, 0) > 1:
-            self.remember_multirow[self.table.col + 1] -= 1
-            self.context.append(' & ')
+        self.table.col += 1
     def depart_entry(self, node):
         self.body.append(self.context.pop()) # header

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值