2016-03-24

Tranlstaion with patterns (Emacs Lisp)

I have following practice problems. I would like to translate them to Japanese and German.
  • The $200$ is the $\\green{\\text{whole}}$. We are trying to find the $\\pink{\\text{part}}$ that makes up $11\\%$ of it:
  • The $25$ is the $\\green{\\text{whole}}$. We are trying to find the $\\pink{\\text{part}}$ that makes up $12\\%$ of it:
  • ...
You might notice these problems differs only inside $$. So, I can replace them with the following regexp by emacs's query-replace-regexp function.
  • The $\(.*\)$ is the $\(.*\)$. We are trying to find the $\(.*\)$ that makes up $\(.*\)$ of it:
  • $\1$ は $\2$ です.私達はその $\4$ となるだけの $\3$ を探しています:
You might also notice, you can see a pattern from this sentence
  • The $200$ is the $\\green{\\text{whole}}$. We are trying to find the $\\pink{\\text{part}}$ that makes up $11\\%$ of it:
to
  • The $\(.*\)$ is the $\(.*\)$. We are trying to find the $\(.*\)$ that makes up $\(.*\)$ of it:
I thought this is done by the following function:
  • (query-replace-regexp "\\$[^\\$]+\\$" "$\\\\(.*\\\\)$")
However, "\\$[^\\$]+\\$" doesn't match $\\green{\\text{whole}}$.

I don't know why this doesn't work, so I wrote the following small program. This works well.

(let ((finishp nil))
  (while (null finishp)
    (progn
      (setq match-start (search-forward "$" nil t))
      (setq match-end   (search-forward "$" nil t))
      (setq finishp (or (null match-start) (null match-end)))
      (if (null finishp)
          (progn
            (kill-region match-start match-end)
            (insert "\\(.*\\)$"))))))

But I am puzzled why this regexp ("\\$[^\\$]+\\$") doesn't match. Can anyone explain me that?

2016-03-04

Super Tuesday

I am visiting US. Coincidentally, there was the super Tuesday. Some news  show Trump's domination. His motto is ``Make america great again''. However, his definition of word `great' is quite different from I know. He wants to build a wall on southern border and Mexico should pay it. He doesn't believe climate change. He wants to remove the public health care. He wants to bomb ISIS. He wants to restore the death penalty. (See http://www.nytimes.com/interactive/2016/us/elections/donald-trump-on-the-issues.html)

Currently, he is winning. I have a problem to understand of his definition of 'great'. If there is a problem inside a country, then the reason is outside (e.g., Mexico wall). If there is a problem, he just doesn't believe that (e.g., climate change), and so on. If he won, I am afraid what he would do. I can easily imagine it is a war to one of (or some of) ISIS, Russia, China, Mexico, some of Islamic countries, .... I am also afraid who actually fight in such war. If I remember correctly, he also mentioned the US is always protecting alliance, so next the alliance should fight. I cannot imagine the EU follows him, but then, Japan and Korea are most likely. I hope my imagination is all wrong. But I also feel my hope may be quite fragile.