When typesetting with both Chinese and English (or other western languages), we may feel that they are squeezed too close together. In fact, a space is desired between Chinese and English texts. E.g., we prefer 中文 English 混合 over 中文English混合. This issue has been much resolved in Word or XeTeX (cctspace can be used for CJK in LaTeX to add tilde before and space after English texts), but on webpages, in Adobe Illustrator / InDesign and many other software, the manual adjustment can be tiresome. So I wrote a simple script to solve this issue. It automatically adds spaces between Chinese and English characters, remove spaces before and after Chinese punctuations as well as consecutive spaces. Hope this small tool can be useful to you.
Continue reading “Spaces between Chinese and English Text”
Category: Technical
Rope cut in random
Pythagoras Tree
Least Error Cartesian Meshing
This is actually the Project Euler problem of last week – I know it’s not good to post the answer of new problems here, but this is indeed a very intriguing problem. In short, the problem is as follows: Given a unit circle within radius of 1, we try to represent it by non-uniform mesh. N lines are inserted into the square [-1, 1] x [-1, 1]. Cells are colored red if they overlap with the unit circle, black otherwise. Find the way to make the red area minimum. Here is my solution on N = 16. Continue reading “Least Error Cartesian Meshing”
How many loops if I randomly knot?
How many 3-pters do I need to have a 3-hit?
Backslashes in WP LaTeX
Just newly upgraded to WordPress 3.4.1, and I’m dismayed to find that whenever I try to type a LaTeX formula, the backslash disappears. I have to replace \ with \\, but every time I do a save, the two becomes one, and next time it becomes none. After some investigation, I finally got the culprit:
/wp-includes/load.php
function wp_magic_quotes() { // If already slashed, strip. if ( get_magic_quotes_gpc() ) { $_GET = stripslashes_deep( $_GET ); // $_POST = stripslashes_deep( $_POST ); $_COOKIE = stripslashes_deep( $_COOKIE ); } // Escape with wpdb. $_GET = add_magic_quotes( $_GET ); $_POST = add_magic_quotes( $_POST ); $_COOKIE = add_magic_quotes( $_COOKIE ); $_SERVER = add_magic_quotes( $_SERVER ); // Force REQUEST to be GET + POST. $_REQUEST = array_merge( $_GET, $_POST ); }
Comment out this line and everything’s fine.
png support for Emacs
Notes on Computational Electromagnetics
Today I uploaded an old set of notes (in CHINESE) that I made when I was in grad school. Check it out if you are interested:
Sudoku Solution – Project Euler #96
This is a Python solution for Project Euler #96, to find the solution for sudokus.
The speed is modest (0.750s with pypy on Windows 7 @ i5 2.60GHz), but the code is relatively short and hopefully the idea is clear. Enjoy.
1. Find candidates for all items. If only one exists for a blank, fill it in.
2. Note down the blank with least but more than one candidates.
3. Copy the matrix and trial the candidates recursively until all blanks are filled.
Continue reading “Sudoku Solution – Project Euler #96”