Thursday, November 29, 2012

Latex with UTF-8 alias in emacs

Recently I felt I would need something more than auctex in emacs. Then I ended up writing a custom LaTeX-mode myself. Now I guess I no longer need LaTeX-preview anymore, and it's no longer painful to edit long formulas!

This is the .tex file, displayed in a plain mode:


 In my custom LaTeX-mode, it displays as (but it still saves as above):


And of course this is the compile result, as you could expect from the first screenshot figure:


The lisp code is shared. As usual for free shares, it is without warranty and try-outs are at your own risk. On the other hand, the modification on display is based on only font-lock-mode and compose-region. No dirty hacks. Thus should be safe.

https://github.com/tririver/wyTex

I also put some custom settings of auctex in the same file. They are not necessary. The only essential part is the function wyTex-key. This function is actually bi-directional alias. If you can input α, β, etc directly from keyboard instead of \alpha, \beta, etc, then directly input them and in saved file they will be saved as  \alpha, \beta, etc and thus can compile using latex or pdflatex directly.

Here is the wyTex-key function:
(defun wyTex-key (utf8-char tex-command)
        (local-set-key utf8-char 
      `(lambda () (interactive) (insert ,tex-command))) 
(font-lock-add-keywords
'wyTex-mode `((,(concat "\\(\\" tex-command "\\)")
(0 (progn (compose-region (match-beginning 1)
 (match-end 1) ,utf8-char)
 nil)))))
  )
Acknowledgment: Thank Francesco for answering my elisp question. And Thank +Xah for suggesting writing an own mode to learn elisp!

Wednesday, October 31, 2012

Use tasker to create simple applications

Tasker is a powerful tool for Android phones/tablets. It is actually a programming language (without language) that can obtain full control of your device. I am a beginner and just tried a simple task: input arxiv identifier, and let tasker download the paper.

 First create a scene (with name arxiv-get). Add TextEdit element, with "Text Changed" task: "Variable Set" -> Name %arxivId to %new_val .

 Then call this scene: Add a task doing the following things:

 (1) Show Scene. Name: arxiv-get;

 (2) HTTP Get. Server: arxiv.org; Path: pdf/%arxivId; Output File: Download/%arxivId.pdf

(3) Open File. File: Download/%arxivId.pdf

 Choose a icon and add a task shortcut. That's it.

Thursday, October 18, 2012

One key compile latex documents

Here I want press one key to compile latex document, and launch viewer.

The first question you would ask: Isn't auctex's binding C-c C-c doing it?
-- Not quite. The biggest problem is that, preview-latex breaks the generated pdf file. Thus I cannot have preview and the generated pdf at the same time. Also, finding configuration methods is (sometimes) harder than do it yourself.

What the code does:
* One key compile latex document
* Put temporary files into temporary paths
* Open reader (if not already open)
* On mistake, open log file in new frame
* On warning, send desktop-notification

Now implications

Friday, October 12, 2012

关于“自由意志”的一点思考


这些天两次和老师、朋友讨论“自由意志是否存在”的问题。连同自己之前的想法,这里做一些归纳:

1. 什么是“是否存在”。
   这应该是疑问最少的一点。“意志”不需要也不可能完全是“自由”的。只要存在自由的成分即可。不过,如何界定“存在”还是不明确的。下文会提到这一点。

2. 什么是“意志”?
   首先,我认为意志是完全由物质决定的。也就是说完全由大脑的微观状态决定的。同样,意识、潜意识也是完全由大脑的围观状态决定的。具有不同信仰的人可能在这一点上有不同的看法。对于采取不同看法的人而言,我下面的讨论是没有意义的。
   那么,是不是说,意志是幻觉,意志不存在,进而自由意志不存在呢?我想这个结论过于武断。我们应该在承认意志(以及意识、潜意识)存在的前提下讨论自由意志的存在与否,而不是简单地否认意志。
   其实,是否承认意志、意识、潜意识的存在,涉及到如何界定“存在”。我只是愿意界定“存在”,使得意志、意识和潜意识是存在的。这种界定的目的在于:
   a. 使自由意志的讨论有意义。
   b. 承认意志、意识、潜意识的存在有其实用的价值。否则精神层面上的一切讨论都变得没有意义。
   出于以上目的,我把存在界定为呈展(emergent)意义上的存在。这样,意志在大脑微观状态基础上的存在性,可以类比于(非零的)熵在微观状态基础上的存在性。统计意义上,我们只把熵定义为同样宏观状态的情况下,微观状态的计数。这样,即便我们完全知道微观状态,熵仍然是存在的。这种存在性不仅是可以定义的,而且是有用的(否则热力学层面上的讨论将变得不可行)。
   这样,意志应该确实是存在的。并且,简单地用还原论来否定自由意志的存在也是不够的。
   总之,我宁愿把“意志”界定为大脑微观状态的某种宏观体现。具体是哪种,我不知道。意识、潜意识也是相似的定义,只是“某种”的所指不同。

3. 什么是“自由”?
   我认为,自由是在约束之下的选择权。约束就是在一定条件下“无法选择”。包括:
   a. 外界条件的约束,包括当前的和过去的外界条件。体现为人无法选择外界条件完全不允许的选项,例如被切断氧气供应后无法仍然选择正常地继续生活。
   b. 初始状态的约束,包括自身的和外界的初始状态。这和a有交集,但不完全相同。
   c. 量子涨落的约束。从哥本哈根解释来看,量子涨落的约束体现为人无法选择测量过程出现的结果;从多世界解释来看,量子涨落的约束体现为人无法选择自己进入哪个分支世界。
   这里大概c是最有争议的。量子涨落究竟应该看成是自由的体现还是约束自由的体现?这取决于我们把“自由”界定为做出选择的权利,还是(外界对系统的)不可预测性。我认为前者是恰当的。不可预测性是自由的必要条件,但不是等价的。比如说,经典计算机完全按照程序运行,我们知道经典计算机不是自由的。但是,给经典计算机加上一个量子的随机数产生器(目前完全可以做到),经典计算机的结果将不可预测。但是这并不说明经典计算机变成了“自由的”。至少,这不是我理解的自由。

4. 什么是“存在自由意志”?这个问题可以分为几个子问题:
   对于自由的约束,是否完全剥夺了意识“做出选择”的权利(即摆脱约束的权利)?
   -- 是:那么,意志就不是自由的。我倾向于这个答案。这是因为,经典和决定论的意义上,意志的选择权被初始状态的约束剥夺了。而量子的意义上,意识的选择权又被量子涨落的约束剥夺了。于是没有自由。或许我这里过于武断。如果如此,我想从相对明确的定义出发,我的结论是可以明确地被驳倒的。
   -- 否:意识是否利用了被允许的“做出选择”的权利?
      -- 是:意志是自由的。
      -- 否:意志仍然不是自由的。

Wednesday, June 27, 2012

Use LaTeX font in other softwares

Just learned how to use LaTeX font (especial the one used in math equations) in other softwares, say, Inkscape.

The font in math equations is called "Latin Modern Math". It is located at
usr/share/texmf-dist/fonts/opentype/public/lm

in a texlive installation on Linux. For other latex versions it should be in a similar position starting with texmf something.

After installing this font, one can use it in software. And the next question is how to input. The characters in the font can be input using UTF-8 code. The dictionary of correspondence can be found at

http://mirror.csclub.uwaterloo.ca/CTAN/macros/latex/contrib/unicode-math/unimath-symbols.pdf


One can input UTF-8 in emacs using command "ucs-insert".

EDIT (Dec 15, 2012): In a new version of tex-live, the Latin Modern Math font is at usr/share/texmf-dist/fonts/opentype/public/lm-math

Saturday, June 23, 2012

Generating latex-style figures using gnuplot

In a figure, it would be nice that the fonts and formula styles are consistent with the main text. For my case, the main text is in LaTeX, and the plot is generated using gnuplot. Here is how to:

Wednesday, June 6, 2012

PDF annotation in Okular

Finally it arrived. With the Okular coming with KDE SC 4.9 (currently in beta status) and poppler 0.20, annotations in PDF can now saved in Okular and shared with other PDF readers (tested in acroread).

Previously, I knew I could use wine applications; I knew I could use complicated tools like pdfedit; I knew I could edit PDF as drawings and then export; I knew on Evince PDF can be annotated (limited support, cannot remove, sometimes annotations can get lost). But this is the first time that PDF annotation is available for real usage on Linux.

For me, this was the last thing (except gaming) that one could easily do in Windows and not in Linux. Now the gap is filled :)

Thursday, May 31, 2012

See which papers gain new citations

Used an hour to write a 93-line python code, parsing inspires to see which papers got new citations since last check. Works like this:
1 ( 2 )  Quasi-Single Field Inflation with Large Mass
2 ( 2 )  Odd-dimensional de Sitter Space is Transparent
3 ( 2 )  Chain Inflation Reconsidered
4 ( 8 )  Angular 21 cm Power Spectrum of a Scaling Distribution of Co
5 ( 111 )  Dark Energy

... ...
39 ( 12 )  Inflation with High Derivative Couplings

Papers with citations:  39 ;  Citations:  1083

110  =>  111  in  Dark Energy
Save citations (default yes, type n otherwise)?
Citations saved.

Monday, April 16, 2012

Move personal bindings to Hyper- in emacs

I guess everybody who heavily use emacs has a number of his / her own key-bindings. Unfortunately, personal key-bindings (if not too long) could conflict with system ones. If not in one mode, it would happen in another mode.

Now I am happy with my solution: I map left alt to Hyper, and  then bind everything personal to Hyper. The mapping can be done in xmodmap: create a file, say, .Xmodmap, with
clear Mod1
add Mod1 = Alt_L
add Mod3 = Hyper_L
add Mod4 = Super_L
keycode 108 = Hyper_L
Then run xmodmap .Xmodmap (and put it to startup applications so it runs every time when login).

Then in .emacs, set every key-binding you like with Hyper (I set a lot of them. Here are only some samples):
(global-set-key (kbd "H-g") 'goto-line)
(global-set-key (kbd "H-l") 'forward-char)
(global-set-key (kbd "H-h") 'backward-char)
(global-set-key (kbd "H-j") 'next-line)
(global-set-key (kbd "H-k") 'previous-line)
(global-set-key (kbd "H-\\") 'math-eval)
(global-set-key (kbd "H-p") 'my-org-screenshot)
(global-set-key (kbd "<H-SPC>") 'save-buffer)
(global-set-key (kbd "<H-escape>") '(lambda ()   (interactive)   (kill-buffer (current-buffer))))
Another advantage is that I press left alt using thumb. Thumb is much stronger than little figure for frequent use :)

Monday, March 26, 2012

Run mathematica commands in emacs

I would like the following feature: When writing a document in emacs (say, a LaTeX paper), I can write the original expression in a comment line, then execute and get the answer. The idea is to send a string from emacs to a shell script, which runs Mathematica kernel

Here is the realisation:

Monday, March 12, 2012

Cosmic inflation is a form of life?

Cosmic inflation (more precisely, the Hubble patch which is undergoing inflation) is a form of life? Clearly not in common sense. However, according to Wikipedia: Life is a characteristic of organisms that exhibit all or most of the following 7 phenomena: