Hi all

Does anybody know how can we use latex in fortran source code?

Welcome, Milad!

What exactly do you mean by use LaTeX in Fortran? Do you mean to convert LaTeX math to a Fortran expression? Or maybe to evaluate it and return the result? Or something else?

I meant that how can we use latex syntax in fortran language comments , just like how we did it in python docstrings. For example consider that i wrote a subroutine which is implementation of a mathematical expression, so i would like to represent symbolic mode of that expression within my source code.

Or do you mean writing results in an output file using the LaTeX syntax ? And then calling the pdflatex compiler from Fortran ? This could be done with:

```
call execute_command_line ("pdflatex my_fortran_output.tex")
```

(Fortran 2008 and later)

https://gcc.gnu.org/onlinedocs/gfortran/EXECUTE_005fCOMMAND_005fLINE.html#EXECUTE_005fCOMMAND_005fLINE

can we use it for one liner mathematical expressions?

This one line command:

```
$ pdflatex "\documentclass{article} \begin{document} \begin{equation} f(x) = 0 \iff x = 1 \end{equation} \end{document}"
```

is generating a file whose default name is `texput.pdf`

. But I donâ€™t know if it is what you wantâ€¦

I still donâ€™t get it. Letâ€™s consider this snippet:

```
real function square(x)
! Returns the square of a real number.
! $f(x) = x^2$
real, intent(in) :: x
square = x**2
end function square
```

Notice the LaTeX math in the â€śdocstringâ€ť. Letâ€™s assume what you are trying to do works. What does the result do and what does it look like?

The objective could be to include LaTeX expressions in a documentation generated with a tool like Doxygen:

http://www.doxygen.nl/manual/formulas.html

http://doxygen.nl/manual/docblocks.html#fortranblocks

If you use the Sublime code editor, the SublimeFortran Package provides hover over popups for inline Latex math in comments.

Alternatively, I do want to provide good Fortran wrappers for SymEngine to be able to manipulate symbolic expressions from Fortran. I already started at https://github.com/symengine/symengine.f90, but didnâ€™t have time to finish. If anybody wants to help, I would appreciate it.

Thatâ€™s exactly what i meant.

Now what if we build the documentation of this subroutine using a tool such as sphinx-fortran?

will the symbolic mode of this latex line be generated ?

If you use the FORD documentation generator, it is possible to include Latex in comments, see here: https://github.com/Fortran-FOSS-Programmers/ford/wiki/Writing-Documentation#latex-support

Thank you all for your valuable tips

Not sure if I have understood the question, but if this is about documentation alone, Doxygen works well with LaTeX. Thereâ€™s some more discussion here.