Saturday, September 6, 2014

LaTeX: Embedding All Fonts in PDF

Many publishers are cautions about readers' experience and want to ensure all fonts are embedded in PDF files when you send your final camera-ready PDF files in.

We commonly use LaTeX to produce publication grade PDF files. However, some publishers warn about the use of pdflatex to compile LaTeX files to produce PDF files, suggesting pdflatex is the culprit. Perhaps, the problem is rather not with pdflatex, but with the configuration of pdflatex. My experience indicates that default configuration of most LaTeX distributions has already got the configuration right. However, my experience indicates that regardless I use pdflatex or the combination of latex, dvips, and ps2pdf, I have many occasions that not all fonts are embedded.

The issue is actually not with latex, but with figures generated by some third party tools. For instance, if you use Matlab to save figure as an eps file, for instance, the following Matlab script produces an eps file example_signal.eps showing a cosine signal.

num_periods = 10;

freq = 5;
sampling_interval = 1/100;
signal_length = num_periods * 1 / freq;
t = 1:sampling_interval:signal_length;
y = 10 * cos(2 * pi * freq * t + pi / 4);

plot(t, y);

xlabel('t');
ylabel('y');
set(gcf, 'PaperSize', [5 5*0.618]);
set(gcf, 'PaperPosition', [0 0 5 5*0.618]);
print('-depsc', 'example_signal');

Let us convert the eps file to a PDF file.


ps2pdf example_signal.eps
pdfcrop example_signal.pdf


Now let us verify if the resulting PDF file has had all fonts embedded,


pdffonts ./example_signal.pdf
name       type    encoding  emb sub uni object ID
---------- ------- --------- --- --- --- ---------
Helvetica  Type 1  Custom    no  no  no       8  0

The above shows that font Helvetica is not embedded. How do we make sure all fonts are embedded. You must include as the example shows, 5 switches in the ps2pdf command,


ps2pdf \
       -dPDFSETTINGS=/prepress \
       -dSubsetFonts=true \
       -dEmbedAllFonts=true \
       -dMaxSubsetPct=100 \
       -dCompatibilityLevel=1.4 ./example_signal.eps

pdffonts ./example_signal.pdf
name              type    encoding emb sub uni object ID
----------------- ------- -------- --- --- --- ---------
FHQQIQ+Helvetica  Type 1C Custom   yes yes no       8  0


We now see the font is embedded.

Note the following,
  • You must include the 5 switches in the ps2pdf command. If you miss one, fonts may not be all embedded. 
  • The command has no effect on PDF files, even though you can run ps2pdf against PDF files and no error or warning will be reported.

If you have a PDF file, but not its ps or eps file, you can use the steps below to convert the PDF file to a ps file and then convert the ps file back to a PDF file. The new PDF file will have all the fonts embedded, for instance,


pdf2ps example.pdf
ps2pdf \
       -dPDFSETTINGS=/prepress \
       -dSubsetFonts=true \
       -dEmbedAllFonts=true \
       -dMaxSubsetPct=100 \
       -dCompatibilityLevel=1.4 ./example.ps
That is all.

Friday, September 5, 2014

The Stem Crisis: Shortage or Abundance of STEM Graduates

From time to time, some minor voice on the shortage of  STEM graduates starts attract attention. Contrary to more dominant view that not only does STEM shortage exist, it may also be a crisis in the making, a recent IEEE Spectrum article questions whether such a crisis is real, which got my attention. A debate ensures and the discussion continues.

I would like to document the opinions of both sides that  I come across.  I'll come back to update this post when I come across new articles.

Motion: There is a STEM Crisis

For the Motion

Against the Motion

Neutral







    Monday, September 1, 2014

    Bypassing SIM Card and Motoblur Account Setup on Atrix 4G

    From time to time, I get the job to deal with a Motorola Atrix 4G phone. Yes, they are an old model, but we do have a couple of them. Fresh out-of-box, the phone always asks the user to insert a SIM card and set up a Motoblur account. To bypassing SIM card and Motoblur account setup, I follow the instruction in this post, which is pretty handy. Just a convenient jump for myselt, click the instruction below for the steps,

    And to quote, the steps are,
    1. Power off the phone
    2. While holding the "Volumn Down" key, power up the phone
    3. As it is powering up, the phone pauses the boot process and displays boot option. Press the "Volumn Down" button a few times, until "Boot Android (No BP)" appears
    4. Now press the "Volumn Up" key to choose the boot option. The phone will resume the boot process.
    5. When it finishes the boot process, the phone displays a language drop-down menu. Thelanguage selection screen is for Motoblur account setup -- the phone has bypassed the "No SIM card/Emergency calls only" screen.
    6. Hold the "Menu" key at the language selection screen of the Motorblur account setup until the soft keyboard appears
    7. Then press the "?123, ALT, ABC, e" key sequence twice in a row, then type the key sequence "b l u r o f f". Note that quotation marks are not part of the key sequences.

    Sunday, August 31, 2014

    Avoiding automatic indentation when pasting code into vim

    I am a vi user and use vim almost daily. One issue that has troubled me is that vim automatically inserts indentations to already well-indented text when I paste the text, e.g., bibtex entry, program segments, into vim because I enabled "autoindent". A solution to address the problem is to inform vim that you are about to paste and then vim will simply paste the text as is,

    1. In vim command mode, type
      :set paste

    2. Then, in vim edit mode, paste the text
    3. Finally, in vim command mode, type
      :set nopaste

    The credit goes to this Stackoverflow post.

    To make switch the paste option on or off easier, we may map the commands to a key or a key sequence. For instance, we can define a mapping ",p" to switch the paste option on or off in the vim command mode by adding the following code snippet into the .vimrc file (located at the $HOME directory),

    
    let mapleader = ","
    nmap <silent> <leader>p :set paste!<CR>
     \ <Bar>:echo "Paste: " . strpart("OffOn", 3 * &paste, 3)<CR>
    set nopaste
    

    The "echo" part above displays an indicator to show whether the paste option is on or off.

    Saturday, August 30, 2014

    Firefox 64-bit Nightly, Google Account, and FireFtp Addon ...

    I have been a long-time Firefox browser user. Recently I have started using Firefox 64-bit Nightly, the 64-bit Firefox browser that is still in testing.

    My experience suggests that the 64-bit version appears to have a better performance when compared with its 32-bit counter part -- well, this is just my feeling and I don't have objective data to back it up; it could have been the result that I restarted the 64-bit version more often than I did with the 32-bit version that eventually became almost frozen and had to be restarted.

    A definite beneift, perhaps, just a short-term benefit, is that I can continue to use my beloved FireFtp addon.  FireFtp addon somehow did not catch up with version updates of the 32-bit Firefox and is now disabled by the lastest version of the 32-bit Firefox. However, I found that the 64-bit Firefox does not have the problem.

    Besides, my own experience is that the 64-bit Firefox is quite stable and it only crashed a few times in more than a month.

    The only problem that I really need to deal with when I use the 64-bit Firefox is the problem with signing into any Google account, e-mail, blogger (this blogger), voice ... The problem is that  from time to time, when I tried to sign in a Google account after a restart of the 64-bit Firefox, the Google sites report an error,

    Oops! Your browser seems to have cookies disabled. Make sure cookies are enabled or try opening a new browser window.

    The error message puts the blames on "cookies". In fact, regardless, following the steps from Google Support, such as this one, how I enable cookies on the browser, remove any history, and cached items, the problem remains. Finally, I realize that it is not a probem  is not with the cookies at all.

    The solution is quite simple -- it is the 32-bit Firefox. Whenver the problem occurs, I follow the steps below,

    1. Close the 64-bit Firefox immedialy, no need to meddle with cookies, web histories, and caches;
    2. fire up the 32-bit Firefox;
    3. log onto any Google account once using the 32-bit Firefox;
    4. and then close the 32-bit Firefox;
    5. finally restart the 64-bit Firefox.

    Eureka! Wahla! I can now sign in any Google accounts.

    So what's wrong with Firefox 64-bit Nightly? The problem may not be with Firefox; instead it may be a problem with Google, as indicated in this bug report -- I guess in this case the 32-bit Firefox sets the values of the relevant attributes to those that Google expects.


    Problem Adding Google Account to Android Devices

    I was trying to add the required Google Account to an Motorola Android phone and encountered a problem. The error message states,

    Can’t establish a reliable data connection to the server.  This could be a temporary problem or your SIM card may not be provisioned  for data services. If it continues, call Customer Care.
    Google searches produced numerous hits. I tried a few and they did not work for me.

    After a little bit careful investigation, I noticed that the time displayed was far off. Although I checked the "Automatic Update Time" option, the device did not appear to update the time to a correct one. My understanding is that when the time is far off, any security protocol using SSL will not work as it requires the messages are time stamped recently, well, to prevent varous forms of the message replay attacks. Then, I used the following solution and it worked.

    1. Uncheck the "Automatic Update Time" option
    2. Manually set time to a correct one. I  used the clock on my computer as a reference. It does not have to be very precise. But, do note that the time zone on the Android device may not be the one your computer is in. If it is the case, you may use a time reference that is in the same time zone of the Android device (e.g., The Official NIST US Time); or simply set the time zone on the Android device to the time zone of your reference time. 
    3. Now add your Google account. It should work now.

    Tuesday, July 22, 2014

    After Kernel Upgrade VMware Ubuntu Guest Hang During Boot

    I am running a Ubuntu Saucy (13.04) guest and later a Ubuntu Trusty (14.04) guest using VMWare Player on Windows 8.1. What has troubled me is that the guest hangs every single time after the POST screen is shown during boot after I upgraded the kernel. I have to press "Ctrl-Alt-Del" to restart, enter "Advanced Option" from the Ubuntu boot menu and choose an old kernel to boot. I finally figured out how to solve the problem.  The hint of the solution came from my examining the VM log file. The location of the VM log file is on the VMware Player's "About VMware Player" window. From VMWare Player, you can open the window by clicking on the "Player" menu, next "Help", and then "About VMware Player". Below is an example of the "About VMware Player" window.

     

    In the above example, the VM log file is at C:\Users\...\Ubuntu\vmware.log. When the Ubuntu is hangs, at the end of the VM log file, I saw some log messages similar to the below,

    2014-07-22T19:21:19.299-04:00| vmx| I120: GuestRpcSendTimedOut: 
                                              message to toolbox timed out.
    2014-07-22T19:21:19.299-04:00| vmx| I120: Vix: [5648 guestCommands.c:1924]: 
                                              Error VIX_E_TOOLS_NOT_RUNNING in 
    VMAutomationTranslateGuestRpcError(): VMware Tools are not running in the guest
    2014-07-22T19:21:25.635-04:00| vmx| I120: USBGW: Write arbitrator op:13 len:11
    

    My guess is that the VMware Tools is not installed and configured properly for the new Linux kernel. The solution would to reinstall the VMware Tools. Since the Ubuntu guest hangs during boot, I have to find an alternate to do it. Luckily, I can boot the Ubuntu guest into the "Recovery Mode" with the problematic Linux kernel via the "Advanced Option" during boot. 

    I observed two difficulties when I tried to reinstall the VMware Tools in the "Recovery Mode".
    1. When I tried to install the VMware Tools when I switched to shell in the "Recovery Mode" by running <code>sudo ./vmware-install.pl</code>, I observed many warning messages similar to below,
      
      The /tmp directory may be under attack
      


    2. You may have to download the VMware Tools, for which, we need to enable network in the "Recovery Mode". 

    To address the above difficulties, my solutions is,

    1. In the "Recovery Mode", first enable "network" from the list of options.
    2. Then go to shell (by choosing "Drop to root shell  prompt").
    3. Start the sshd. This is a two-step procedure.

      
      mkdir /var/run/sshd
      /usr/sbin/sshd
      
      
    4. Now, figure out the IP address of the guest (e.g., using ifconfig)
    5. Log onto the virtual machine using a Secure Shell client as a regular user with sudo privilege.
    6. Install the VMware player as the regular user using sudo.
    7. Reboot. The the problem went away.