PDA

View Full Version : LaTex it - A code to convert Word to LaTex



Programmer_n
07-03-2020, 09:16 PM
I use VBA to convert word to LaTex using find and replace function of word.


Sub Latex_it()
Selection.Find.ClearFormatting
Selection.Find.Font.Italic = True
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = "\textit{^&}"
.Forward = True
.Wrap = wdFindContinue
.Format = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Font.Bold = True
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = "\textbf{^&}"
.Forward = True
.Wrap = wdFindContinue
.Format = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

The above code adds LaTex tag to italic and bullets respectively.

Is there a more elegant way of doing it and How to select section heading using above code and apply LateX tag

corresponding LaTex tag for word section heading

\section{heading level1}
\subsection{heading level2}
\subsubsection{heading level3}

Paul_Hossler
07-08-2020, 04:19 PM
The above code adds LaTex tag to italic and bullets respectively.

Bullets or bold?

I'd imagine that if you used styles (Heading1, Heading2, ...) a F&R for paragraphs in that style could be tagged.

Programmer_n
07-11-2020, 07:14 PM
Yes bold.

Any idea how to select Heading levels.