Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Latex code from do-files - including markup?

    Hello everyone,

    I am currently working on a paper for uni, and I want to document some of the do-files I used in its appendix.
    As I am typesetting everything in Latex, I am wondering wether a way exists to get nicely looking Latex-code from do-files (ideally, I want to match the syntax markup from the do-file editor, row numbers etc. Absolute icing on the cake would be something that mirrors the left hand brackets that indicate how far loops span.).
    I wasn't able to find anything via google, which perhaps has to do with the fact that I find it hard to find suitable search terms - "Stata" and "Latex" tend to give answers pertaining to conversion of Stata output, and adding "do-file", "code" and the like unsurprisingly doesn't change this...

    Or maybe I am the only one wanting to do such a thing? In that case, I will of course be ok with the second best option of including pdf-printouts from the do-file editor itself.

  • #2
    I'm not sure if I follow, you are drafting document using Latex and you want to introduce snippets with Stata code? In terms of exporting Stata documents, you may have a look at the Ketchup package. Presumably you could blend your Latex output and Ketchup-generated files in one PDF or HTML document, but I'm not sure if this is what you are trying to do.
    Kind regards,
    Konrad
    Version: Stata/IC 13.1

    Comment


    • #3
      Thanks for the quick reply, and sorry for not being clear enough.

      My aim is to append my do/ado-files within a latex document, reproducing the look/markup of Stata's editor as good as possible.

      Thanks for the hint to Ketchup, I'll have a look; from my first impression, it might at least be able to help me get a html version of what I want, which should in turn make further conversion to Latex possible.

      Comment


      • #4
        Would use of the Stata Journal LaTex packages help accomplish what you want to do? (Inclusion of do-file and log-file output is something that the SJ has to deal with routinely.) Googling on "stata journal sjlatex" gives some hits that would help you assess the usefulness of my suggestion.

        Comment


        • #5
          I'd definitely second the suggestion of using the Stata Journal LaTeX packages. Just type "help sjlatex" at the Stata command line.
          In particular, there's a command which takes the entire contents of a Stata log-file (or do-file) and displays it in suitable markup within your LaTeX document, so no need to copy-and-paste the do-file text. There are also markup commands for referring to Stata stuff (commands, manual refs, etc.) within the main body of your document.

          Comment


          • #6
            Make a screenshot to illustrate a point how your code deals with a particular problem. If your code is larger than a screen, don't attach it at all. Retyping it all would be a pain and nobody would do it anyway. Attach a file on a CD. Afaik Stata Journal template is black and white because Stata Journnal is BW. Capturing PDF printout from do-editor is a good option.
            Best, Sergiy

            Comment


            • #7
              Hi all,

              I regularly use LaTeX's package -listings- to achieve embedded Stata code in LaTeX documents. However - if this is what you're after - listings does not enable you to "sweave" your document (i.e. integrate either syntax or output, or both into the document), but only includes a do-file into a LaTeX-document output and typesets it as verbatim.

              listings can also (by defining syntax highighting styles) highlight comments and keywords. Several syntax definition rules (such as C, R or C+) are delivered with the package. Unfortunately, you have to define a style on your own to achieve Stata syntax highlighting.

              Regards
              Bela

              Comment


              • #8
                If you want to export a document in LaTex directly from the dofile, use the MarkDoc pakage. In the current version, you cannot type LaTex in the dofile, but you can use Markdown to type the text and then export it to any format you want. The Ketchup package only exports HTML and PDF. I recommend MarkDoc for combining graphs and Stata outputs and exporting it to any editable format, i.e. LaTex, Docx, etc.
                ——————————————
                E. F. Haghish, IMBI, University of Freiburg
                [email protected]
                http://www.haghish.com/

                Comment


                • #9
                  Here is an update to MarkDoc package. MarkDoc version 1.6 was released some days ago, which allows you to write a dynamic document using LaTeX, directly in Stata dofile editor. I have written a blog post about it which I link below. If you choose to write with LaTeX instead of Markdown, you should export in tex format, and of course, you should avoid writing with Markdown and LaTex at the same time.

                  Link to blog post: http://www.haghish.com/stata-blog/?p=32

                  Link to example dofile (recommended): ​http://www.haghish.com/talk/reproduc...rkdoc_latex.do
                  ——————————————
                  E. F. Haghish, IMBI, University of Freiburg
                  [email protected]
                  http://www.haghish.com/

                  Comment


                  • #10
                    Originally posted by Daniel Bela View Post
                    listings can also (by defining syntax highighting styles) highlight comments and keywords. Several syntax definition rules (such as C, R or C+) are delivered with the package. Unfortunately, you have to define a style on your own to achieve Stata syntax highlighting.
                    Someone already designed a listings syntax highlighting style for Stata: https://gist.github.com/kongs-sublim...ings-stata-tex

                    Comment


                    • #11
                      Originally posted by haghish View Post
                      There is no page at that URL ("404 - page not found").

                      At http://haghish.com/statistics/stata-...ch/markdoc.php it says:

                      Note that MarkDoc requires additional software that are downloaded and installed automatically once you begin working with MarkDoc. But you need to be the Administrator of your machine.
                      Could you please be more specific about the additional software? Some users may not be comfortable installing a package that downloads unknown additional software, especially if that unknown software requires administrator rights.

                      Comment


                      • #12
                        Originally posted by Friedrich Huebler View Post
                        Could you please be more specific about the additional software? Some users may not be comfortable installing a package that downloads unknown additional software, especially if that unknown software requires administrator rights.
                        1. Friedrich, the website is not updated for a long time. Sorry for the broken links. I'm finishing my PhD in a month and then spend the time to renew my website.
                        2. The current version of MarkDoc does not download any software automatically. This was already fixed a year ago.
                        3. MarkDoc package requires Pandoc software. You can install it manually from pandoc.org.
                        4. For those who don't want to bother with manual installation, MarkDoc provides optional automatic installation.
                        5. At the moment, the only reliable documentation for MarkDoc is the help file. The syntax has considerably changed in version 3 and older examples will no longer work.
                        6. The current version of MarkDoc is 3.5. The link you referred to belongs to version 2.1
                        ——————————————
                        E. F. Haghish, IMBI, University of Freiburg
                        [email protected]
                        http://www.haghish.com/

                        Comment


                        • #13
                          @haghis, good luck finishing up the dissertation! I hope it goes (or went) well.

                          I also hope you're in conversations with Stata Press two write a book on this package. I don't see any other books on it or similar packages (though I've just started my search for such in Stata). Lots of Stata books have something on reproducibility (and SJ Long's "Workflow" is my bible), but I haven't seen a full book on reproducible documents (e.g., Latex, Markdown) yet.
                          ****************************
                          Survey Methodologist
                          California Health Interview Survey

                          Comment


                          • #14
                            Matt Jans, thanks for your kind words. Actually I am preparing the content for a Stata book. But I am also trying to "Finalize" MarkDoc and Weaver. Writing a book requires the packages to be near "perfection" and for that, I want them to be thoroughly tested by the Stata community. I am preparing a new release for both and I think they are somehow reaching a reasonable maturity.
                            ——————————————
                            E. F. Haghish, IMBI, University of Freiburg
                            [email protected]
                            http://www.haghish.com/

                            Comment


                            • #15
                              That's great to hear! I'll try to work them into my workflow in a project. I'm committed to Stata, and this is one area of my workflow I'd really like to improve. Everyone seems to be focused on doing it in R, but for me, Stata works better (several reasons, but one is their survey data support). If you need a reviewer for the draft text, don't hesitate to recommend me to Stata press. If I have the time I'll be happy to review. I'll want to buy and read this anyway.
                              ****************************
                              Survey Methodologist
                              California Health Interview Survey

                              Comment

                              Working...
                              X