Posts

Showing posts from August, 2008

Custom text in figures with Latex

Image
Building on my last post, I am still talking about writing up engineering calculations with LaTeX. Since then, I have discovered XFig. It is like a mini CAD program that allows you insert LaTeX text into your figures which is then processed when the document is compiled. The basic procedure is explained on XFig's site. I use xfig to generate diagrams with custom LaTeX macros instead of numbers. This way, if the value changes, the changes are written out automatically by the spreadsheet and the figure is updated when the document is recompiled. Lovely. As an example, I have created the following figure below: Notice the LaTeX code in math mode in the figure. The macros are defined in the .tex file on the second and third lines. They begin with \newcommand: You can see the resulting values have been inserted into the figure in the final PDF document.

Custom variables with Latex and Excel

I often have to write up engineering calculations for my work. Often I use LaTeX because of its excellent handling of equations, references, and custom variables. My strategy is to do the calculations in Excel, then create custom variables in a variables.tex file that contain all the values from my spreadsheet that will appear in the write up. I do this because if there is an error in my calculation, I can just change the value in one place and it will be corrected everywhere in the document where it appears. Unfortunately, I sometimes have to deal with 50 or 100 values. Manually changing those even in only one place can quickly become time consuming, so I wrote the following Excel macro to automatically write the variables.tex file for me when I save the spreadsheet. Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Const texFileName As String = "variables.tex" Dim FileNum As Integer Dim curLabel As String Dim curValue As String FileN