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!