Japanese Text With LaTeX!

November 23rd, 2008 Pekk

Okay when I did this I was really only looking for Japanese. The simplest way to do this (and I’m on a MacX machine using TeXShop) was to use XaLaTeX, and use the fontspec and xunicode packages.

I found a PDF file online that was actually just like a tex input file, but in pdf format (probably so that the fonts would be visible without any encoding issues).

First thing it said you need are these two lines:


%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

The first one is to force TeXShop to use XaLaTeX, and the second is to force it to save the tex files in utf-8 format.

Somewhere after the document class we add the following


\usepackage{fontspec,xunicode}
\defaultfontfeatures{Mapping=tex-text} %% !!IMPORTANT!! This preserves out fancy tex text like ` for left quote -- for en dashes, etc.
\newfontfamily{\J}[Scale=0.85]{Osaka} %%this is our macro for changing to japanese font mode, enclode all jp text with {\J Whatever}

The scaling on the japanese text is totally optional, personally i kind of like it without, but i have noticed that the Osaka font is more bold.
Now we can apply the japanese text anywhere in our document:


Word. {\J ????????? ???????}

Since I’m so sure the encoding on that got clobbered (I don’t know why though, this blog used to be UTF-8 Friendly…) I’ve included a sample file. So check the Japanese Text in TeX Example out. Make sure your browser is set to UTF-8, or just right-click Save (Link, Target) As… Check out the resulting Japanese Text in TeX Example PDF File.

The basic idea of the technique is just to switch fonts to a system font that will have japanese character support :) Osaka is one of them. Mac users can check the Font Book application to scour for more.

Posted in General | No Comments »

More Unix Fun!

July 30th, 2008 Pekk

Just now I was poking through some files on my Slackware machine. I went roaming through /etc/profile to add an option I found online that adds auto-complete to commands using sudo. I decided to add the command at the bottom of my /etc/profile (to allow all users to have it). The line added was:

complete -cf sudo

Additionally, while poking through on my slack machine I discovered the source to one of the many joys of Slackware: random quotes when bash starts! On startup, the default profile (/etc/profile) script runs through all *.sh files in /etc/profile.d and executes them (if the files have +x permissions). One of these files is named bsd-games-login-fortune.sh (on my slack machine I also had a script for csh as well). So I opened up this script to have a look and found this:

#!/bin/sh
# Print a fortune cookie for interactive shells:
if [[ $- = *i* ]]; then
echo
fortune fortunes fortunes2 linuxcookie
echo
fi

At a quick glance you can see the main program (or possibly script) behind everything is this fortune thing. So I exit vim, and type ‘fortune‘ on the command line, and voila~ Then I typed ‘which fortune‘ and I see it’s installed in /usr/games/. ‘file /usr/games/fortune‘ tells me it’s an executable, so I scurry back to my mac to check macports for a “fortune” package.  I bring up my terminal:

sudo port install fortune

I now have fortune on my mac :) To add it to my start up, I take a look back at the bsd-games-login-fortune.sh script:

#!/bin/sh
# Print a fortune cookie for interactive shells:
if [[ $- = *i* ]]; then
echo
fortune fortunes fortunes2 linuxcookie
echo

The lines in bold are the ones I didn’t understand. Pretty terrible, right? First off I had to figure out what the double brackets ([[ and ]]) meant for bash. After some swift googling I found out that [[ and ]] can do a few things for us.

  1. We do not have to quote variables (i.e., “$MYVAR”) when doing checks, though it is still recommended.
  2.  Word  splitting and pathname expansion are not performed on the words between the [[ and  ]];
  3. [[ and ]] allow us to use wildcarded comparisons *I THINK, this is an observation based on the context of this script*

Well there were a few other things too but I lost the page now and I can’t find it :( for a much longer reading. For more information check man bash. Look in the section that starts:

 [[ expression ]]
Return a status of 0 or 1 depending on  the  evaluation  of  the
conditional  expression expression.  Expressions are composed of
the primaries described  below  under  CONDITIONAL  EXPRESSIONS.
Word  splitting  and pathname expansion are not performed on the
words between the [[ and  ]];  tilde  expansion,  parameter  and
variable  expansion, arithmetic expansion, command substitution,
process substitution, and quote removal are  performed.   Condi-
tional operators such as -f must be unquoted to be recognized as
primaries.

The next thing I didn’t understand was the $. I found a page explaining $- on the net by searching for himBH which is the string I kept getting when I did echo $- in a terminal window. It turns out this returns the current shell options, which is kind of funny because I somewhat guessed this when I saw the output, I assumed i means interactive. This info is also available in the bash manpages.

Next up is the fortune fortunes fortunes2 linuxcookie line. What the hell was this supposed to mean? I did a man fortune as it turns out, this is just giving extra files for fortune to read from, which are all located in /usr/share/games/fortune/ (on Slackware) and if you’re really bored one day you can just cat them and read away :)—but I think it’s better not to spoil the surprise :D unfortunately when I copied this script line-for-line (I just put it directly in my /etc/profile, instead of making a separate script for it) I was getting errors that my fortune binary couldn’t be found. Well the reason is that its in /opt/local/bin, and (for me anyway) this path hasn’t been added to my path yet (and doesn’t get added until my ~/.profile is sourced). To fix that I just put the full path name /opt/local/bin. The same will be necessary for the files, too. On my macports MacX install they’re located by default in /opt/local/share/games/fortune/. Have yourself a look in this path and you can even add a couple more fortune files that aren’t in by default!

MacX Users:

ls /opt/local/share/games/fortune/

Linux Users:

ls /usr/share/games/fortune/

Again, those are just defaults. If you chose to do a manual install (which I didn’t explain here anywhere) then you obviously know where your fortune files should be ;)

But wait! There’s more! I was now more curious than ever. I did a grep Welcome /etc/* and found exactly what I was looking for in /etc/motd. That annoying “Welcome to Darwin!” message. I wanted to change it to say “Welcome to `hostname`.” which is also tacky—I felt was a little improvement on the original, but apparently the motd (”message of the day” in case anyone is wondering) doesn’t seem to evaluate anything like a bash script would. I changed mine so now it says “Welcome to Darwin!! :D” After doing some more research I found out that the motd can be surpressed by creating a file named .hushlogin in your home directory. So I brought up my terminal to test it out:

touch ~/.hushlogin

And then I hit Command + N for a new terminal (MacX) and *poof* my motd is gone :) check man motd for more info.

BUT WAIT THERE’S MORE!

I also figured out how to change the sensitivity on my mouse on my Slackware so it’s not so insane. My friend at work helped me with this one:

xset m 1 1

Thanks, Nikolay!

Alright that’s really all I got for you  now. Later!

Posted in Mac OS X, Slackware, Linux | 1 Comment »

Configuring Fluxbox Shortcut Keys!

July 24th, 2008 Pekk

Hey! I’m back already! Did you miss me? Probably not, but I do have some very useful news! I’ve just discovered how to set up keyboard shortcuts on Fluxbox. Although it is very easy the only reason I’m writing this short article is because I was have some slight issues trying to get Fluxbox to recognize my ; and ‘ keys in the ~/.fluxbox/keys file. So here’s a short guide on how to add shortcut keys on to your fluxbox.

If I didn’t already disclose it to you directly enough the file you’ll be editing is ~/.fluxbox/keys and mine looks something like this:

OnDesktop Mouse1 :HideMenus
OnDesktop Mouse2 :WorkspaceMenu
OnDesktop Mouse3 :RootMenu
OnDesktop Mouse4 :NextWorkspace
OnDesktop Mouse5 :PrevWorkspace

Mod1 Tab :NextWindow
Mod1 Shift Tab :PrevWindow
Mod1 F1 :Workspace 1
Mod1 F2 :Workspace 2
Mod1 F3 :Workspace 3
Mod1 F4 :Workspace 4
Mod1 F5 :Workspace 5
Mod1 F6 :Workspace 6
Mod1 F7 :Workspace 7
Mod1 F8 :Workspace 8
Mod1 F9 :Workspace 9
Mod1 F10 :Workspace 10
Mod1 F11 :Workspace 11
Mod1 F12 :Workspace 12

Just from looking at the file it’s not too hard to tell what’s going on here. The file appears in the format:

Key Code Combination :command

From what I’ve read the space before the semicolon is important otherwise your commands won’t work. You can put any keys here with any modifiers. To get a list of your currently mapped modifier keys use the xmodmap utility, and it will give you some output, for example:

(73) .fluxbox/ $ xmodmap
xmodmap: up to 3 keys per modifier, (keycodes in parentheses):

shift Shift_L (0×32), Shift_R (0×3e)
lock Caps_Lock (0×42)
control Control_L (0×25), Control_R (0×6d)
mod1 Alt_L (0×40), Alt_L (0×7d), Meta_L (0×9c)
mod2 Num_Lock (0×4d)
mod3
mod4 Super_L (0×7f), Hyper_L (0×80)
mod5 Mode_switch (0×5d), ISO_Level3_Shift (0×7c)

If this seems confusing to you let me explain–if you want to use the ctrl key (according to what my xmodmap output says) I would use control, for example if I wanted Ctrl + Tab to switch to next workspace I could do:

Control Tab :NextWorkspace

And to make Control + Shift + Tab go backwards (which would make sense):

Control Shift Tab :PrevWorkspace

(The name of your modifier key is the output of the first column from xmodmap) if you’re still not sure exactly which column to read (for whatever the reason may be) it may be easier to read the output of the following command:

xmodmap |cut -d ‘ ‘ -f 1

Which, for me (following the same output I had above) would now give us this new output:

(87) .fluxbox/ $ xmodmap |cut -d ‘ ‘ -f 1
xmodmap:

shift
lock
control
mod1
mod2
mod3
mod4
mod5

For a list of more commands you can hotkey, check out the commands listed at the fluxbox wiki keyboard shortcuts page
Now for most of you, you should be pretty satisfied with what you’ve learned so far. But for me, of course this wasn’t enough. Why? Because I couldn’t figure out for the life of me how to get fluxbox to recognize my damed ; and ‘ keys! Then
as I searched the net more and more thoroughly I came across a wonderful solution: xev
Using the xev command we are able to view key strokes and their names (along with other miscellaneous x events. So I fire up my xev (it gives a whole bunch of output from startup) and when it’s ready I hit my ; key. The output (after releasing the ; key) looks something like this:

KeyPress event, serial 32, synthetic NO, window 0×1200001,
root 0×3f, subw 0×0, time 1480794821, (602,218), root:(654,288),
state 0×0, keycode 47 (keysym 0×3b, semicolon), same_screen YES,
XLookupString gives 1 bytes: (3b) “;”
XmbLookupString gives 1 bytes: (3b) “;”
XFilterEvent returns: False

KeyRelease event, serial 32, synthetic NO, window 0×1200001,
root 0×3f, subw 0×0, time 1480795069, (602,218), root:(654,288),
state 0×0, keycode 47 (keysym 0×3b, semicolon), same_screen YES,
XLookupString gives 1 bytes: (3b) “;”
XFilterEvent returns: False

What we’re looking for here is what comes after the keycode i.e., (keysym 0×3b, semicolon) in this example. The same process can be used for any key. So now I’ve added the following to my fluxbox keys file at the bottom:

#Greg’s Custom Mods
#Workspaces—————–
Control Shift J :Workspace 1
Control Shift K :Workspace 2
Control Shift L :Workspace 3
Control Shift semicolon :Workspace 4
Control Shift apostrophe :Workspace 5
#moving windows to specific workspaces
Control Mod1 Shift J :SendToWorkspace 1
Control Mod1 Shift K :SendToWorkspace 2
Control Mod1 Shift L :SendToWorkspace 3
Control Mod1 Shift semicolon :SendToWorkspace 4
Control Mod1 Shift apostrophe :SendToWorkspace 5

#Programs——————-
Control Shift I :Exec xterm
Control Shift O :Exec firefox

#Windows——————–
Mod1 W :Close
Mod1 Shift M :Maximize
Mod1 Shift N :ToggleDecor

More will come later! Good luck and happy flux-ing!

Posted in Linux | No Comments »

Fluxbox Menus That Stick!

July 24th, 2008 Pekk

I found this post saved here and since I thought it was kind of relevant to Fluxbox and the customizations I’ve been working on, I figured I’d finally post it ;D


While at work I was using a Vector Linux machine that loaded with Fluxbox, I’ve used BBLean for windows for a while so I’m someone used to the menu driven system. The fluxbox, however worked different than the bblean I had at home. Whenever I right clicked on fluxbox at work I had to hold down the right click button to select items from a list, this was different from at home where I could just click once and the right click menu would stay.

A colleague helped me fix this problem. By doing some web searching he found that to change the fluxbox menu to stay when it is right-clicked all that’s required is to change one line in the init file.

in ~/.fluxbox/init change the menuMode from:

session.screen0.autoRaise: false
session.screen0.resizeMode: Bottom
session.screen0.menuMode: Delay
session.screen0.colPlacementDirection: TopToBottom
session.screen0.sloppywindowgrouping: true

to:

While at work I was using a Vector Linux machine that loaded with Fluxbox, I’ve used BBLean for windows for a while so I’m someone used to the menu driven system. The fluxbox, however worked different than the bblean I had at home. Whenever I right clicked on fluxbox at work I had to hold down the right click button to select items from a list, this was different from at home where I could just click once and the right click menu would stay.

A colleague helped me fix this problem. By doing some web searching he found that to change the fluxbox menu to stay when it is right-clicked all that’s required is to change one line in the init file.

in ~/.fluxbox/init change the menuMode from:

session.screen0.autoRaise: false
session.screen0.resizeMode: Bottom
session.screen0.menuMode: Delay
session.screen0.colPlacementDirection: TopToBottom
session.screen0.sloppywindowgrouping: true

to:

session.screen0.autoRaise:  false
session.screen0.resizeMode:  Bottom
session.screen0.menuMode:  Click
session.screen0.colPlacementDirection:  TopToBottom
session.screen0.sloppywindowgrouping:  true

Posted in Computers, Linux | No Comments »

Customizing XTerm

July 24th, 2008 Pekk

Since I’m now using fluxbox I decided to try out something else that’s a bit new to me: xterm. If you’ve ever seen an XTerm window before you might agree that its appearance is rather bland and dull, so after some super brief research I’ll post the changes I made.

First thing I did (which I do with all of my terminals) is change my prompt. that “bash$” prompt is just so boring! My settings however are pretty extreme—since the escape sequences are very confusing in large quantities I divided my prompt into separate variables which then all combine to make the final PS1. I placed the following in ~/.bashrc (note on my Mac I have this stuff in ~/.profile)


TITLEBAR="\u@\h \w"
TITLEBAR="\e]2;$TITLEBAR\a"
CURDIR="\W"
HISNUM="\[\e[37m\](\[\e[32m\]\!\[\e[37m\]) "


export PS1="\[$TITLEBAR\]$HISNUM\[\e[33m\]$CURDIR\[\e[37m\]/ \[\e[32;1m\]\\$ \[\e[0m\]"
export PS2="\[\e[32;1m\]>\[\e[0m\] "

For more information about customizing your prompt, check out Gentoo’s awesome documentation, Prompt Magic. The next thing of course, since my terminal prompt uses white foreground colors was to change the background color of my xterm. After some brief searching I found out about a file called .Xdefaults in the home directory which can be edited. My ~/.Xdefaults looks like this now:


xterm*background: #000000
xterm*foreground: #FFFFFF

Since I just was not happy with my `ls’ output, I went back to ~/.bashrc and added the following alias for ls:


alias ls="ls -F --color=always"

That’s it for today! I’ll be back with some more customizing tips later! PEACE!

Posted in Computers, Linux | No Comments »

The Return of the Slackware!

July 24th, 2008 Pekk

Recently I’ve rescued my old Toshiba laptop which had a broken optical (DVD/cd drive) by removing its hard drive and placing it in yet another broken laptop. This [Compaq] machine’s optical drive worked, but not the monitor! In any case I installed Slackware 12 on my Toshiba’s laptop hdd via the Compaq, and swapped the drives back. As soon as I saw Lilo loading my slack I got so excited! So now I’ll be fiddling a bunch with slackware and posting my findings here. I’m using Fluxbox as my main WM so there will be lots of customizing to do!

Posted in Slackware, Linux | No Comments »

Alt Left-Click Resizing for Metacity/Gnome

November 6th, 2007 Pekk

Here’s a quick fix to change metacity’s <Alt> + Middle Click resize to <Alt> + Left click to resize. Nikolay, a friend of mine found a patch file for it on the web, the code’s pretty simple just swapping a couple of numbers. I just read a few lines from the file he discovered on someone’s blog. I didn’t really bother to read the rest of it but Nikolay explained a bit more on how to build a deb package from the source and install it once the modifications are applied.

If you don’t want to get your hands dirty on compiling you can try installing my version using dpkg -i metacity_2.20.0-0ubuntu3_i386.deb once you download the file. I do not guarantee this file in any way, use it at your own risk. Follow on to learn how to patch it yourself.

First install the following packages. I used apt-get from the terminal, since I’m on Ubuntu (root permission is required):

$ sudo apt-get build-dep metacity

$ sudo apt-get install devscripts debhelper fakeroot

Now CD to the directory that you want to download the metacity source files to and type:

$ sudo apt-get source metacity

You won’t have permissions to the source files, so you will have to either edit them as root, or chown them to your user:

$ sudo chown -R metacity*

once you’re ready, cd to the metacity/src folder (in my case it was metacity-2.0/src). Now you have to make a change in the display.c source file, on my version of the source it’s line 1665 so it should probably still be around there. Use any text editor that you’re comfortable with (I used vim). The original line looks as follows:

else if (!unmodified && event->xbutton.button == 2)
{
if (window->has_resize_func)
{
gboolean north, south;
gboolean west, east;
int root_x, root_y;
MetaGrabOp op;

Change this to:

else if (!unmodified && event->xbutton.button == 3)
{
if (window->has_resize_func)
{
gboolean north, south;
gboolean west, east;
int root_x, root_y;
MetaGrabOp op;

And then the next change should be the next else if that’s connected to our currently modified if. Around line 1714 in my code looks like this:

else if (event->xbutton.button == 3)
{
if (meta_prefs_get_raise_on_click ())
meta_window_raise (window);
meta_window_show_menu (window,
event->xbutton.x_root,
event->xbutton.y_root,
event->xbutton.button,
event->xbutton.time);
}

Make it look like this:

else if (event->xbutton.button == 2)
{
if (meta_prefs_get_raise_on_click ())
meta_window_raise (window);
meta_window_show_menu (window,
event->xbutton.x_root,
event->xbutton.y_root,
event->xbutton.button,
event->xbutton.time);
}

If you want to test drive your changes before making anything permanent you can optionally make a test build, from terminal:

metacity/src $ cd ..

metacity/ $ make

metacity $ ./src/metacity –replace

This will (1) build metacity and (2) run it by replacing the currently opened process with the new one we built. try moving the terminal window around with the new left-click mod for a bit to make sure it works, when you’re satisfied send the break command with Ctrl+C to kill the process, and your original metacity will reopen.

Now we are going to build our very own debian package. Why? I don’t know but this is how Nikolay suggested to do it, I was going to just do a make install when the compiling finished after I’d tested it, but he told me to do it this way so I didn’t question it. At least this way you’ll have a deb package to distribute to your friends.

At the terminal in the metacity/ directory type:

$ debuild -us -uc

It will now recompile everything for you and place a bunch of deb packages in one directory up from the current. (i.e., if the metacity source path is ~/src/metacity then the deb packages will be placed in ~/src)

Now install the deb packages with dpkg:

dpkg -i name_of_your_metacity_package.deb

There will be a few deb files, make sure you get the one that says metacity and not libmetacity.

I will also post a patch file when I finally remember how to correctly use patch (or maybe I’m just not creating the diffs right, either way I will post back soon).

Another easy way to make this change is to apply the following diff. To do this, place the patch file in the same directory as your display.c (in the metacity/src path) and issue the command:

patch < right-click-resize.patch

from a terminal window. The patch was created as a context diff (diff -c) so if patch won’t take this (though it did for me) you can try an explicit call as follows:

patch -p0 -c < right-click-resize.patch

Happy Hacking!

Posted in Ubuntu, Linux | 2 Comments »

Ubuntu Missing C Manpages

November 5th, 2007 Pekk

Today I tried looking up some C functions in the manpages on my ubuntu and noticed that they were missing. As it turns out, Ubuntu does not by default install the manpages developer package. To install the C reference man pages install the following packages via apt-get:

apt-get install manpages manpages-dev

If you’re still having problems try also:

apt-get install manpages-posix manpages-posix-dev

The latter is what worked for me but then I found out about the manpages-dev package, and most likely this package includes the posix-dev, but I’m not 100% sure.

Posted in Ubuntu, Linux | No Comments »

Ubuntu Desktop Icons and Right Click on Desktop Not Working!

October 29th, 2007 Pekk

Last night I installed the new Ubuntu Gutsy and encountered some problems after customizing it.The desktop icons would not show and the right click on desktop did not work… I did some googling and found the following tip:

gconftool-2 –type bool –set /apps/nautilus/preferences/show_desktop false

This was found on a forum post about gtk2.10 having this issue and nautilus trying to intercept the right click… I tried this but it didn’t work - then i realized i didn’t install gtk+ 2.10 yet and so i change false to true and it worked again.

gconftool-2 –type bool –set /apps/nautilus/preferences/show_desktop true

was the answer to my solution. I’ll post more later about my new Ubuntu escapades, but for now I gotta run :D

Posted in Ubuntu, Linux | No Comments »

Microsoft® Windows® Japanese IME Shortcut Keys

September 14th, 2007 Pekk

Since this is always something I’m forgetting, and it is a very important bit of information I’ll make this quick post to get the information up here.

The default keyboard shortcut for the Microsoft® IME to switch between languages is left alt + shift. This can be changed through the IME options though. Once you’re in Japanese mode the shortcuts are as follows:

  • Switch to Hiragana - alt + caps lock
  • Switch to Katakana (from Hiragana) - alt + capslock again.
  • Switch to Hiragana (from Katakana) - ctrl + capslock
  • Switch to direct input - alt + ~

I don’t think this is how it’s supposed to work, but this is how it seems to work for me, if I’m stuck in Katakana I can hit ctrl+caps to get back to Hiragana. But this is only what I’ve noticed for the Final Fantasy XI Windower IME plugin. I don’t really use my windows for anything else.

A document I found online stated:

Control + Shift:   This switches between IME languages (ie. between English & Japanese, and back again).
     
Control + CapLocks:   This shortcut switches to katakana input mode.
     
Control + CapLocks
(Twice quickly):
  This shortcut switches to hiragana input mode.
     
Control + ~ :   This switches between the current input mode and the English (Latin script — direct input) mode within the Japanese IME.

This might work better for other applications.

Posted in Japanese | No Comments »