Skip to content

Method to write LaTeX-ready documents using MS Word and some Powershell commands together with Pandoc

License

Notifications You must be signed in to change notification settings

AnaHill/Write-LaTeX-documents-using-Word

Repository files navigation

This is short example how to write LaTeX documents using Word.

Even though you know LaTeX (or you are willing to learn it), this repo can be useful when

  • your supervisor(s) and/or co-authors are not familiar with LaTeX, in other words you can not share LaTeX document with them
  • you do not want to manually move their comments, edits, and texts to your LaTeX-document

This method was used to write the following publication freely available in this link

A. -J. Mäki, J. T. Koivumäki, J. Hyttinen and P. Kallio, "Simulation-Based Study of Control Strategies for Beating of Human Cardiomyocyte Cultures," in IEEE Transactions on Automation Science and Engineering, doi: 10.1109/TASE.2023.3309668.

Working principle is to write Word-document with some LaTeX-command. Firstly, write you document in Word with LaTeX-commands that are used to include citations and references, symbols, figures, tables, and equations using LaTeX. Then, convert the Word-document to .tex using the Powershell script (worddoc_to_tex.ps1). If needed, upload (e.g. if using Overleaf) the converted .tex file so that your main/root LaTeX document (WriteLaTeXusingWord.tex in this example) can find it. Then, you can build the final document e.g. using pdflatex. Flowcharts below illustrates the working principle. For more detailed information, see Word-document or converted pdf-file.

flowchart flowchart

Additional support: level up section heading level

Current version will create \section headings in converted .tex file for those lines that are written as Heading 1 level on your Word-document, \subsection for Heading 2, etc. However, if your LaTeX-document class is for example book, you should probably increase each section level, so that each \section would be \chapter, each \subsection would be \section, and so on. In this case, additional script increase_section_level.ps1 can be used to make this conversion automatically:

$modified_file_name = 'main_text.tex' # give file name to be edited
(gc $modified_file_name) | % {$_ -replace "\\section{", "\chapter{"} | sc $modified_file_name
(gc $modified_file_name) | % {$_ -replace "\\section*{", "\chapter*{"} | sc $modified_file_name # abstract etc non-numbered chapters
(gc $modified_file_name) | % {$_ -replace "\\subsection{", "\section{"} | sc $modified_file_name 
(gc $modified_file_name) | % {$_ -replace "\\subsubsection{", "\subsection{"} | sc $modified_file_name  
# optional: convert \paragraph to \subsubsection and \subparagraph to \paragraph, uncomment if needed
# (gc $modified_file_name) | % {$_ -replace "\\paragraph{", "\subsubsection{"} | sc $modified_file_name  # typically not used
# (gc $modified_file_name) | % {$_ -replace "\\subparagraph{", "\paragraph{"} | sc $modified_file_name  # typically not used

Acknowledgment

I warmly thank Juhana Ketola for his pro bono help related to PowerShell. Thanks to my current and former colleagues, Sampo Tuukkanen, Mikko Peltokangas and Ville Rantanen helping with LaTeX, especially introducing catchfilebetweentags package, developed by Florent Chervet. Special thanks for Florent, your work saved me a lot of time! Furthermore, “tom’s” (sorry, couldn’t find author information, please share!) great blog post in texblog helped to implement catchfilebetweentags package.

About

Method to write LaTeX-ready documents using MS Word and some Powershell commands together with Pandoc

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published