Romaji yen sign in Terminal in the UTF-8 encoding

Hello all,

I have a MacBook Pro with a Japanese keyboard running Mac OS X 10.6.2. In Romaji mode, the Japanese keyboard has a dedicated yen sign (¥) key, and Option-¥ produces a backslash (\). In Terminal, for some reason, the ¥ key produces \ without the Option modifier. (Option-¥ also produces \ in Terminal, which is normal behavior.)

A similar situation was discussed in an older topic, http://discussions.apple.com/thread.jspa?messageID=10665836 , where the problem was diagnosed as having the Shift JIS encoding enabled in Terminal. However, this doesn‘t reflect my situation, since the only encoding that is enabled in my Terminal is UTF-8 – and there‘s certainly a yen sign available in UTF-8.

I am able to type other UTF-8 characters in Terminal in Romaji mode; for example, I can type Option-e e to produce é, and entering the command *echo é | od -x* within Terminal shows that the correct UTF-8 byte sequence is generated for é. Since the command *echo -e '\0302\0245'* within Terminal will produce a yen sign there, the problem seems to be connected to the key mapping rather than to a stty interface problem.

Is there anyone running 10.6.2 with a Japanese keyboard who can type the ¥ key in Romaji mode in Terminal with the UTF-8 encoding enabled, and have a yen sign appear rather than a backslash?

(This topic was initially posted in the +Installation and Setup+ forum, and I‘ve taken the advice of a kind soul there to repost the topic in this forum.)

MacBookPro5,5, Mac OS X (10.6.2), Japanese keyboard

Posted on Mar 15, 2010 7:13 PM

Reply
20 replies

Mar 20, 2010 9:39 PM in response to Tom Gewecke

It seems iTerm does still more brute force conversion from ¥ to .
For example, if you turn on the Hiragana mode of Kotoeri, enter えん (for example by hitting e n n) and convert it to ¥ by hitting space several times, and hit return to input ¥ to iTerm, then it is converted to by iTerm. This does not happens in Terminal.app. It seems the only way to input ¥ to iTerm is copy/paste.
I guess the reason that this has not been a major problem so far is only because there are very few people who need ¥ in iTerm.

If you download the source code of iTerm, then you will find the following code at around line 753 of PTYSession.m (in method insertText):

if ([mstring characterAtIndex:i] == 0xa5) {
[mstring replaceCharactersInRange:NSMakeRange(i, 1) withString:@"\"];
}

If you comment out this line and rebuild iTerm then it seems all of the ¥ to conversion is disabled.

Mar 21, 2010 12:34 PM in response to Jun T.

Jun, the forced ¥-to-\ conversion is a useful feature for programmers who are restricted to using encodings that have a yen sign and don’t have a backslash — namely JIS X 0201 and its strict supersets, such as Shift JIS — simply because JIS X 0201 specified having a ¥ in the \ position of ASCII. That historical background is the reason why Japanese keyboards by default don’t have backslashes available through unmodified or shifted keypresses. I wonder if JISC (the Japanese organization that corresponds to ANSI in the USA, DIN in Germany, &c.) has specifications that mandate which keys Japanese keyboards should have?

On the MacBook Pro Japanese keyboard, the Control key is to the left of the A key, the Caps key is in the lower left corner, and the Option key is next to the Caps key, “southwest” of the Z key, directly “south” of the Q key. I’ve only seen a picture of its US analogue, but it looks like it has a Caps Lock key to the left of the A key, the Fn key in the lower left corner, and the Ctrl key next to the Fn key, directly “south” of the 1 key. It also looks as though the US Tab, Caps Lock, and (left) Shift keys are wider than their Japanese analogues: the Japanese Tab key is the same width as the Q key, the Control key is the same width as the Command key (20 mm), and the Shift keys are about 29,5 mm wide. I think that this is the reason that I find using Option-¥ for \ to be no problem; my Option key is precisely where your Ctrl key is. Perhaps you would find “optioning” not so burdensome if you had your Ctrl key next to your A key, and your Option key where your Ctrl key currently is?

I agree that those who press Option-y in Terminal would certainly be more likely to expect ¥ than \, even if ¥-to-\ were expected for a ¥ key. This seems to reïnforce the theory that it is the ¥ character that’s being substituted rather than the keystroke(s) that usually produce ¥, in which case it would be a both-or-neither choice — and at this time it’s unalterably both.

Mar 21, 2010 12:49 PM in response to Jun T.

Jun, thanks for pointing that out. I had filed [an iTerm bug report for this|http://sourceforge.net/tracker/?func=detail&aid=2973966&group_id=67789&ati d=518973] mainly because I couldn’t find a link from which its source code could be downloaded! Where did you find the download link?

Tom, my thoughts were that it might have been a “feature” of one of the Cocoa functions, since only Terminal and iTerm are known to have this behavior; but if it’s due to just a hard-coded if-block in each program, then it shouldn’t be too difficult to patch the programs to make ¥-to-\ conversion a user-selectable preference.

Mar 21, 2010 9:53 PM in response to Baumkartoffel

Where did you find the download link?

If you visit http://sourceforge.net/projects/iterm/develop then you will find an instruction:

svn co https://iterm.svn.sourceforge.net/svnroot/iterm iterm

Just type this at your shell prompt. Then a new directory "iterm" is created and the source code is downloaded into it. But it seems all the subversion files are downloaded. You need only iterm/branches/0.10.x/.

$ svn co https://iterm.svn.sourceforge.net/svnroot/iterm iterm
$ cd iterm/branches/0.10.x
--- edit PTYSession.m ---
$ make
....
** BUILD SUCCEEDED **

Then the new iTerm.app is in the subdirectory build/Development/.

Mar 23, 2010 8:07 PM in response to Jun T.

Jun, thanks for the link. I had expected source packages to be available in the iTerm download section, and was surprised to see that only binaries were available there. I need to update the bug report there with your findings …

The author of KeyRemap4MacBook has made some additions to it on my behalf, and version 6.5.10 has the capability to allow either Option-y or a ¥ key to produce ¥ in Terminal. (Despite the name, it isn’t exclusively for MacBooks; but this version only runs on Snow Leopard. The author has an earlier version that runs on Tiger and Leopard, but I don’t know whether it is still maintained.) Here’s how to set it up:

• Download [KeyRemap4MacBook 6.5.10|http://pqrs.org/macosx/keyremap4macbook/files/KeyRemap4MacBook-6.5.10.pk g.zip] (or a later version, once available) and install it. Restart the computer.

• After logging in again, click on the hollow key-shaped icon on the top bar. (Sorry, I don’t know the usual Apple name for the top bar.) Click on “Open KeyRemap4MacBook PrefPane”.

• On its preference pane, in the Mapping tab, click on “Remapping for Applications”. Once it’s expanded, click on “Enable at only Terminal”. Once that’s expanded, select the “Remap Option+y to F18” checkbox. Close the preference pane.

• Open Terminal’s Preferences. Under the Settings tab, choose your preferred setting, and click the Keyboard tab within that setting. Scroll down to the F18 key, and replace its default action (\033[32~) with ¥ (i.e. Option-y). Close Terminal’s Preferences.

• Try typing Option-y in a Terminal window of your preferred setting. You’ll know that it’s working if a ¥ appears instead of a \.

• For people with Japanese keyboards, who would like the ¥ key to produce ¥ in Terminal, open the KeyRemap4MacBook preference pane again, select “For Japanese”, then its own “Remapping for Applications”, then its own “Enable at Only Terminal”, then select the “JIS Yen(¥) to F18 (if no modifiers pressed)” checkbox. Close the preference pane, and go back to the Terminal window. Press the ¥ key, and see if ¥ shows up instead of \.

There, that wasn’t so hard, was it? ;*)

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Romaji yen sign in Terminal in the UTF-8 encoding

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.