Friday, December 29, 2023

How to convert a Latex file to Microsoft Word

I prepared a manuscript in latex but had to submit it in .docx format. Here are the steps I took to generate a Word manuscript: 

1. Use revtex and set the format to preprint. 

2. Open a command window in Windows and run the following command: 
    
    htlatex yourfile.tex HTML  

3. Open the generated html file in Microsoft Word and change the fontsize to 12 and line spacing to 1.5 lines. 

4. The reference links in the manuscript do not work properly. To remove these hyperlinks, select all ("CTRL+A") and press CTRL+SHIFT+F9. 

5. There is no line break in the bibliography. For a better format, use PDFLatex to generate a PDF manuscript instead, convert it to Word using Adobe's free online tool (or that comes with Adobe Acrobat), adjust the page margins to be the same as the html file in Word, and copy the bibliography to the html file. 
 
6. The equations are converted to pictures. Double click them to adjust their sizes if needed. 
 
7. These pictures are linked to the png files generated by htlatex. They will not display in a different folder or on a different computer. To convert them to embedded pictures, go to File->Info->Show All Properties, and click "edit the links to this file." Then check the box at the bottom that says "save pictures" or something similar and click the button on the right to remove links. 

Now, you may ask me why not directly edit the Word file generated by Adobe Acrobat. The issue is that many subscripts of inline maths are converted to pictures or letters in a separate line, which are very difficult to edit one by one. The same issue exists for a few other online converters I found. 

If you know a better way to complete this task, please do not hesitate to let me know!

(Updated on Jan 2, 2024: I just discovered that arxiv now provides an HTML version of the submitted manuscript. The downloaded HTML file is very complicated though and does not display properly in Word. Also, pay attention to the order of the references in a single citation. They are ordered and grouped automatically by latex in PDF/DVI output but not in HTML, as each reference has its own hyperlink.)

Monday, December 14, 2020

Research.gov margin problem

Recently I prepared a proposal using Research.gov instead of Fastlane. I liked the more modern look of it and the option to upload PDF files without apparent compression.

The feature I found a bit annoying is the automatic margin check. I prepared a document using Microsoft Word with one inch margins on all sides and printed it using the PDF printer that came with Windows 10. However, this output file could not pass the margin check. Initially I thought there might be a problem with the imbedded figures, but after an hour of fine tuning the figure positions and sizes, the problem persisted. Just as I was going to give up and switch back to Fastlane, I noticed that there were a few puctuation marks that seemed to stick out to the right ever so slightly, and these turned out to be exactly the culprits! Reducing their sizes from 11pt to 9pt saved the day.

I hope this tip can save you some time if you stumble upon this post. Another tip: Do not include page numbers! It also triggers the wrong margin flag. Remove them and the system will automatically add them at the very end.

Tuesday, October 11, 2016

Matlab colormap problem

My laptop has MatLab 2014b and for some reason it cannot save edited colormaps. As an alternative, I found a good online tool that allows you to generate 256-bit colormaps conveniently. Check out the link below and see whether you like it. (Note: Chrome does not seem to work well with this website.) http://jdherman.github.io/colormap/ 

Wednesday, May 20, 2015

Shining eyes in the desert

I took this photo on my way to San Jose. In it you see a pair of shining eyes deep in the (Mojave?) desert. Any idea what they are? (see the answer below)

 
If I'm not mistaken, they are reflections of the Sun by a solar thermal power plant. And here is a different view of this plant.




Thursday, February 26, 2015

Stuck with A4 size in revtex and how I solved it

I was setting up Miktex 2.9 on my new laptop, and revtex just couldn't output any other paper size than A4 when the setting was clearly changed. I then decided to see whether the documentclass[...]{revtex4} had something to do with it, and I was happy to find that by changing it to {revtex4-1} solved the problem.  

Friday, July 25, 2014

Extract numerical values from the names of your data file

Well, you generated a series of fantastic data by varying some parameter, which was used to name your data file. Now you need to process these data again but then realize that you didn't save the values of this parameter. What can you do? I hope that you are not thinking of copying every single value in the file names!

Here is how you can do it using awk in two lines. Say the file names are in the following format: "xxxxx_1.553_fsolve.mat." First you save all the file names as a txt file:

ls *fsolve.mat > namelist

Then do the following:

cat namelist | awk '{split($0, a, "_"); print a[2]}' > namelist2

$0 is the stdout from "cat namelist"; "a" is a string array generated from $0 with the delimiter "_", and in our case it has three elements: a[1]="xxxxx", a[2]="1.553", and a[3]=".mat". What remains to finish the task is to print a[2] to a file ("namelist2").

To better understand the use of split, we can accomplish the above using one more split command

cat namelist | awk '{split($0, a, "_fsolve"); split(a[1],b,"_"); print b[2]}' > namelist2

See how it works :)

Thursday, July 24, 2014

Collection on Art of Science (Part I)

One appeal of doing research on photonics is that the results, once properly illustrated, can really be amazing.  Here I am showing two pov-ray illustrations that were generated based on the lasing modes I calculated in random lasers and wave-chaotic microcavity lasers. The authors of these figures are Rob Tandy and Omer Malik, who worked with me on these projects at Yale and Princeton. If you are interested, read more following this link (http://www.eng.yale.edu/stonegroup/science.html) on random lasers. The "butterfly" one will be published soon (hopefully). Keep tuned in!



Thursday, June 13, 2013

Dell Vostro V131 BIOS recovery

I was trying to update the bios of my Dell V131 laptop from A03 to A06 last weekend, and inexplicably the update window disappeared and the fan started to run very fast. For some reason I decided to shut down the laptop, which started my nightmare.

The laptop couldn't start. The power and wifi LEDs lighted up when I pressed the power button, followed by the flashing of the three accessory LEDs. Dell logo did not appear and the fan hummed momentarily. The laptop was just over one-year old and Dell's customer service wanted $59 for a one-time diagnosis fee!

I started searching online and found many helpful informations on mydigitallife.info, especially in the master thread for bios recovery procedures (http://forums.mydigitallife.info/threads/870-Bios-Recovery-Procedures).  Dell's customer service told me that the bios of my laptop was made by AMI, but the methods given in the above thread did not work. So I started blindly trying all the methods listed in that thread for AWARD and Phoenix BIOS, and it was a no-go.

At that moment I started to wonder whether my motherboard was fried as well. I knew from my trials that the laptop still read from the USB key, but it didn't recognize an attached USB floppy drive. Was it able to detect the other components? I removed the rams and without them the laptop did give two short beeps. So I thought to myself that the motherboard was most likely fine.

Well, life had to go on and I did have another laptop that I could use. So I put the bricked laptop aside while thinking of other possible recovery means. I visited a Chinese website biosrepair.com which also had a lot of information. In its forum there was even an post with the extracted bios file for V131. To my surprise, the file had an BIN extension, which suggested the bios was made by AWARD from my readings, yet the methods suggested in the thread at mydigitallife.info for AWARD didn't work.

My success finally arrived after I came across a post on recovering Insyde bios (http://forums.mydigitallife.info/threads/13095-Undocumented-INSYDE-BIOS-recovery-method-Use-andy-s-tool-to-obtain-possible-names). The tool (pheonix214.exe) linked in this post showed that my bios was actually "EFI/Insyde." I couldn't help cursing the Dell customer service guy who gave me the wrong information, but later it turned out that he was actually right. Anyway, here are the procedures that worked for me:

1. Use HP USB Disk Storage Format Tool with MiniDOS files to make the USB key drive bootable.

2. Execute the Dell BIOS update application (V131A06.EXE) in a command window with /writeromfile and /writehdrfile options, respectively. Rename the generated files "V131.HDR" and "DJ5A06.ROM." These names are the ones given by pheonix214.exe when analyzing the EXE file.

3. Remove the battery and plug in the USB key drive. While holding down WINDOWS and B keys, insert the power cord. Wait for a few seconds and press the power button. Keep holding the keys until the light on the USB key drive starts to flash.

I can't remember exactly what happened after I performed these procedures, but the screen lighted up in a few seconds with the Dell logo! Then I just followed the on-screen instructions to update the bios, and my miserable four days were finally over. OK. I admit that I almost made another mistake here. After rebooting, the laptop complained about the lack of a bootable device. Did I just ruin my SSD?! I scratched my head only to realize that I didn't put it back after backing up my files!

Now to the innocent Dell guy. It turned out that the bios is indeed made by AMI, but it is a special line called Aptio, which I learned in the recovered bios.

Wednesday, June 5, 2013

What's wrong with simulating photonic crystals with more than one unit cell?

I thought that I had a good understanding of band structures in 1D photonic crystals. Yesterday I did a simple test by comparing the band structures calculated using one unit cell with periodic boundary condition (PBC) and 3 unit cells with PBC. It turned out that the results were different! In the latter case additional bands are found, which are the images of the original ones shifted by \Delta k = 2\pi/3a and  4\pi/3a (a: the period of the lattice). So what went wrong?

I did additional tests with 2,4,5 unit cells. And the images are shifted by {\pi/a}, {\pi/2a, \pi/a, 3\pi/2a},  {2\pi/5a, 4\pi/5a, 6\pi/5a,8\pi/5a}, respectively. Considering that the distances shifted are integer times of 2\pi/(whole width of simulated structure), I gradually realized that somehow I was simulating structures with a period of the whole width, instead of the intended, smaller width of the unit cell. Why would this happen?

There are two possibilities: (1) The machine error makes each of the unit cell in the simulated structures slightly different, so the true period of the simulated structures is in fact the whole width. (2) Somehow imposing the PBC on the whole structure does not guarantee that the solutions are Bloch waves \psi(x) = exp(ikx) u_k(x), with u_k(x) = u_k(x+a).

Take the simulation with 3 unit cells for example. Indeed I found that the two shifted images of the original (correct) band structures correspond to waves with u_k(x) = u_k(x+3a) only, which confirms (2) and implies (1). Interestingly, |u_k(x)| = |u_k(x+a)| does seem to hold for these two images. Why? One can understand this observation from a physical point of view, since the system is still quasi-periodic and the probability of finding photons (electrons) at the same position in different unit cells should still be roughly the same.

A variant of what I observed is the following: Simulating the same total width but reducing the period of the structures by an integer n. One would have expected only part of the band diagrams in [-\pi/a,\pi/a], since the Brillouin zone now is [-n\pi/a,n\pi/a]. But due to the slight difference of each unit cells, one ends up with the whole folded band structures.

Monday, June 3, 2013

Batch processing raw photos

A good start is to convert all the raw photos into jpeg for quick viewing:

ufraw-batch --out-type=jpeg *.*

Of course one probably want to create a new folder with the newly taken photos, so that the new jpegs do not overwrite the old ones by mistake.

Tuesday, May 28, 2013

"Signature field(s) detected" in Adobe reader

I found it quite annoying that a green banner showed up in  Adobe reader every time I compiled a pdflatex file. To prevent this green banner from showing up, I found the instruction in this link (http://try67.blogspot.com/2013/05/acrobatreader-disable-sign-pane.html) which suggests a registry trick to set "HKLM\SOFTWARE\Policies\Adobe\(product name)\(version)\FeatureLockdown\cServices\bEnableEchoSignDetection" to 0. Unfortunately the key was not there on my laptop. I had to create the key and then the value by hand. Note that the latter should be created as a DWORD.

Thursday, May 23, 2013

Reduce size of PDF files with embedded JPEG

I found this fantastic feature of ghostscript:

gswin64c -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dPDFSETTINGS=/ebook -sOutputFile=C:newFile.pdf C:originalFile.pdf

Sources:
http://www.itechies.net/blog/archives/1764
http://www.alfredklomp.com/programming/shrinkpdf/

Tuesday, April 2, 2013

Optomechanics project revisted

1. The two-time correlator of the collective polarization/inversion operator does not scale with the square of the atom numbers. It scales with N instead, since we assume there is no correlation between two different atoms.

2. When applying the Wierner-Khinckin theorem with operators, do not make the Fourier transform of an operator A^\dagger(w) =[A(-w)]^*. Keep all the operators as they are but perform the identity for their prefactors if needed.

Monday, July 2, 2012

Using box.net as the dav server in Zotero

Check the workaround in
http://forums.zotero.org/discussion/20351/

"Possible workaround: The problem might just be that there's a delay before uploaded files are available, which would be a problem for the server verification but possibly not for a normal Zotero file sync. You can try going to about:config in the Firefox address bar (or clicking "Open about:config" from the Advanced pane of the preferences in Standalone) and setting extensions.zotero.sync.storage.verified to true, which will override the server verification and let you try to sync. No guarantees, obviously."

The setting in Zotero is https://www.box.com/dav/zotero.

Friday, February 10, 2012

Matlab: Fatal error on startup: Failure loading desktop class

Updating jre messed up matlab configure file again. Removing classpath.txt in ~ fixed the problem.

MacPro CD/DVD tray problem in ubuntu

I was able to eject a cd/dvd in unbuntu 9 from the command line using "eject." Somehow it doesn't work anymore in 11.10, neither does "eject /dev/cdrom" or "eject cdrom" work. By going into the /dev directory, I found that cdrom is just a link for sr0 in my MacPro, and "eject /dev/sr0" did the job! There is also a sr1 which I thought was the 2nd tray in MacPro, but "eject /dev/sr1" didn't do anything.

Wednesday, January 18, 2012

Fix bcd the elegant way

Oh well, I messed up the bcd and the Win 7 installation CD didn't find the OS installed. Then I tried bootrec /rebuildbcd, which found one out of two installed OS, but it couldn't continue and complained that bcd is being used by another process.


bootrec.exe /fixmbr bootsect.exe /nt60 all /force
cd C:\boot
attrib -h -s BCD del BCD
bcdedit /createstore bcd.temp bcdedit.exe /store bcd.temp /create {bootmgr} /d "Windows Boot Manager" bcdedit.exe /import bcd.temp bcdedit.exe /set {bootmgr} device partition=C: bcdedit.exe /timeout 10 attrib -h -s bcd.temp del bcd.temp
bcdedit.exe /create /d "Microsoft Windows" /application osloader
bcdedit.exe should return a message with a GUID for the newly-created entry, something like this:
The entry {c0dfc4fa-cb21-11dc-81bf-005056c00008} was successfully created.

Then use this number/entry and type 

bcdedit.exe /set {c0dfc4fa-cb21-11dc-81bf-005056c00008} device partition=C: bcdedit.exe /set {c0dfc4fa-cb21-11dc-81bf-005056c00008} osdevice partition=C: bcdedit.exe /set {c0dfc4fa-cb21-11dc-81bf-005056c00008} path \Windows\system32\winload.exe bcdedit.exe /set {c0dfc4fa-cb21-11dc-81bf-005056c00008} systemroot \Windows
bcdedit.exe /displayorder {c0dfc4fa-cb21-11dc-81bf-005056c00008}

In my case the XP is on C: and Win 7 on E:. However, the winload.exe is missing in the XP partition(?), so I had to try a second time and set all the "C:" above to "E:" which solved the problem.

Another thought: Maybe I should have changed the attribute of the bcd file and tried /rebuildbcd? Anyway, the problem is now fixed.

Updated: A similar but more complete guide was found on http://idoneitmyself.wordpress.com/2009/11/15/windows-7-suddenly-wont-boot-reboot-and-select-proper-boot-device-or-insert-boot-media-in-selected-boot-device-and-press-any-key-repairing-the-windows-7-bootloader/

Monday, December 5, 2011

"Hold and drag" in windows 7 stopped working

Solution - "control+alt+del" then "esc"

Monday, November 21, 2011

Squares shown in places of Chinese characters

In Windows Enterprise Chinese characters in folders and other places (like the title bar in chrome) are not shown correctly. This problem does not exist in the home premier edition. A simple solution is to change the system locale to Chinese and then change back to English. Still, I wonder how MS let this slip though their quality control. I now see more evidences of the failing of MS and the rising of Apple.

Friday, October 21, 2011

Uninstallation a program in windows after registry clearner failed

Recently I swapped the hard drives between two laptops. HP's programs on one of them refused to be uninstalled in the new laptop. Manual registry removal the entries in

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall

helped, but it also brought some other HP programs back which I thought had been uninstalled. Next phase of using all sorts of registry cleaners did not work. So there we go - manually search for all entries with "hewlett" in the registry. Bingo! They were located in

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products.

After deleting them the entries in the program list were finally gone.