code 高亮 to tex。html2tex.pl

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

code 高亮 to tex。html2tex.pl

#1

帖子 eexpress » 2011-12-20 11:16

lstlisting 颜色不丰富。
------------------------------------------------------------------------------------------
Vst.vim 不行。
------------------------------------------------------------------------------------------
● highlight -S perl -i test.pl -o test.tex -L
结果,需要修改:
增加
\usepackage{xeCJK} %中文字体
\setmainfont{Vera Sans YuanTi} % xeCJK
去掉
#%\ttfamily

老问题,highlight 颜色不丰富。

------------------------------------------------------------------------------------------

vim的:ToHtml,然后 gnuhtml2latex,html2tex.pl 没颜色,只有粗体。

html2ps, ps2eps(计算BB),然后\epsfig{figure=test.eps,height=32em},颜色可以,空白太多,要先调整html。中文乱码。
● 鸣学
头像
yjcong
帖子: 2470
注册时间: 2006-02-28 3:11

Re: code 高亮 to tex

#2

帖子 yjcong » 2011-12-20 12:23

配色难道不是自己可以调节的吗?貌似emacs很方便吧
一梦三年,
松风依旧,
萝月何曾老.


灵幽听微, 谁观玉颜?
灼灼春华, 绿叶含丹.
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: code 高亮 to tex

#3

帖子 eexpress » 2011-12-20 13:24

手动调整,太傻了点。
lstlisting 没变量高亮。否则我也将就调了一个desert颜色。
还是vim自动输出最好看。

如果老没方案,又自己写一个算了。
● 鸣学
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: code 高亮 to tex

#4

帖子 eexpress » 2011-12-21 16:17

html2ps 真复杂,还可带配置文件。还只能在配置里面指定页面尺寸。

http://user.it.uu.se/~jan/html2psug.html
Please let me know if you are aware of any free PostScript fonts for Chinese, Korean, etc.

perl都直接使用utf8了。这家伙,,,

中文麻烦,直接改ps也不行。中文被转成
● echo 视频|uni2ascii -a K
\350\247\206\351\242\221

只好用trim=7 280 200 7,crop这样调用eps了。
● 鸣学
头像
leni
帖子: 1989
注册时间: 2008-09-28 17:24

Re: code 高亮 to tex

#5

帖子 leni » 2011-12-21 20:25

变量也要高亮啊。 :em06
latex 是个命令集,不是软件,所以在应用程序里找不到,也不存在启动。使用的话,自己写个 .tex 的文件,用 latex 编译。viewtopic.php?f=35&t=331555 的 4楼 有入门教程PDF下载。
头像
Methuselar
帖子: 122
注册时间: 2009-06-04 12:06
联系:

Re: code 高亮 to tex

#6

帖子 Methuselar » 2011-12-22 11:46

我一般

docutils + pygment => tex source. 效果一般般
Mea Culpa!
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: code 高亮 to tex

#7

帖子 eexpress » 2011-12-22 14:38

使用vim的tohtml输出为xx.html

代码: 全选

● html2tex.pl xx.html >xx.tex
tex里面,使用

代码: 全选

\input{xx.tex}
就可以得到全彩色的代码段。

目前2个问题:
1. 颜色太多了。不知道能设置颜色堆栈深度不。
** WARNING ** Color stack underflow. Just ignore.
** WARNING ** Color stack underflow. Just ignore.
2. 空格使用\quad不好看。
附件
网页和pdf对比图
网页和pdf对比图
html2tex.pl.tar
(10 KiB) 已下载 71 次
● 鸣学
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: code 高亮 to tex

#8

帖子 eexpress » 2011-12-22 15:35

搞不定颜色堆栈,改导言区去定义颜色就麻烦了。

暂时使用这设置变量。
identifierstyle=\bf\color[HTML]{98FB98},
● 鸣学
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: code 高亮 to tex

#9

帖子 eexpress » 2011-12-24 1:07

改成了使用hash颜色表。

步骤
vim使用:Tohtml输出 xxx.html。
执行

代码: 全选

● html2tex.pl xxx.html >xxx.tex
在 xxx.tex 的尾部,会提示如下。需要加入导言区的颜色定义。

代码: 全选

% add below lines before document.
%\usepackage{xcolor}
%\definecolor{mycolor5}{HTML}{FFA0A0}
%\definecolor{mycolor3}{HTML}{CD5C5C}
%\definecolor{mycolor6}{HTML}{FFDEAD}
%\definecolor{mycolor4}{HTML}{F0E68C}
%\definecolor{mycolor1}{HTML}{333333}
%\definecolor{mycolor7}{HTML}{98FB98}
%\definecolor{mycolor}{HTML}{FFFFFF}
%\definecolor{mycolor2}{HTML}{FFFF00}
%\definecolor{mycolor8}{HTML}{87CEEB}
测试文档类似。

代码: 全选

\documentclass{article}

%\usepackage{xeCJK}
%\setmonofont{Courier 10 Pitch}
%\setmonofont{Vera Sans YuanTi Mono}

\usepackage{xcolor}
\definecolor{mycolor5}{HTML}{FFA0A0}
\definecolor{mycolor3}{HTML}{CD5C5C}
\definecolor{mycolor6}{HTML}{FFDEAD}
\definecolor{mycolor4}{HTML}{F0E68C}
\definecolor{mycolor1}{HTML}{333333}
\definecolor{mycolor7}{HTML}{98FB98}
\definecolor{mycolor}{HTML}{FFFFFF}
\definecolor{mycolor2}{HTML}{FFFF00}
\definecolor{mycolor8}{HTML}{87CEEB}

%------------------------------
\begin{document}
\input{xxx.tex}
\end{document}
效果和vim的一模一样。
附件
screenshot21.png
html2tex.pl.tar
(10 KiB) 已下载 62 次
● 鸣学
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: code 高亮 to tex

#10

帖子 eexpress » 2011-12-25 0:21

● git df
diff --git a/html2tex.pl b/html2tex.pl
index dfa239e..856e8e7 100755
--- a/html2tex.pl
+++ b/html2tex.pl
@@ -8,7 +8,7 @@ $_=join "", grep /<body/, @_;
/text="#(.*?)"/; $textcolor=getcolor($1);
/bgcolor="#(.*?)"/;
print "\\colorbox{".getcolor($1)."}{
-\\begin{minipage}{\\textwidth}
+\\parbox{\\textwidth}{
\\ttfamily
";

@@ -27,13 +27,12 @@ s|<font color="\\#(.*?)">(.*?)</font>|"\\color{".getcolor($1
s"<b>(.*?)</b>"\\textbf{$1}"g;
s/<.*?>//g;
next if /^$/;
-#s/\\color.mycolo.*?}\\color/\\color/g;
+s/\\color\{mycolor\d*\}\s*\\color/\\color/g;
s/$/\n/g;
print;

}
-print "\\end{minipage}}\n";
-print "
+print "}}
% add below lines before document.
%\\usepackage{xcolor}
";
● 鸣学
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: code 高亮 to tex

#11

帖子 eexpress » 2011-12-25 13:54

2个版本。反正怎么精简,都会颜色堆栈溢出。大约显示18行的彩色无误。

https://github.com/eexpress/eexp-bin/bl ... l2tex-s.pl
https://github.com/eexpress/eexp-bin/bl ... tml2tex.pl
● 鸣学
回复