Announcement

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

  • Suppressing output in log-file (for markdoc)

    Hi statalisters,

    I'm trying to create a log file that only shows my commands, not my output (to some extent, a reversed "quietly", if you want to).

    Is there a way of doing this?

    Please note that I don't want to comment out all of my commands - I would like to keep them active.

    Background on this: I'm trying to use markdoc to pass my dofile and its markup to LaTeX. As a sidenote, I've seen the other, related, post, and I've already tried sjlatex as an alternative - but don't think it works for me.

    Thanks for your help,

    Andy
    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

  • #2
    Hi Andy

    There are many ways you can do that. But frankly, I am not sure what you are about to do!

    My guessing was that you want to use MarkDoc package to write a document using "markdown" and export it to "LaTeX". And now you want to write some commands that you want them to appear in the LaTeX document, but without any output. But then, why did you say "a reversed quietly"? Because in my opinion, a reversed quietly would mean something like "showing the output only and removing the command" which in MarkDoc version 3.3 you can do by adding /**/ before any Stata command.

    For example, if you want to hide a regression command and only include the output table, you'd write:

    . /**/ regress price mpg

    Which will let MarkDoc know, you are not interested in the command. But if in Contrast, you just want to include the commands, and ignore the outputs, use quietly prefix or if you don't want to use quietly, define a code block in your document. A code block will tell the compiler that this text should not be interpreted as regular human language and be included as is. This is how you can do it in MarkDoc. Note that a code block is placed as comment and "cannot be executed." With the current version of MarkDoc, "quietly" is the only option of actually running the codes and omitting the output. However, if you use Weaver Package, you can be much more selective of the content of the document. Anyway, this is an example of how to do it in MarkDoc:


    qui log using example, replace

    /*
    Defining a code block in MarkDoc
    ================================

    ~~~~~~~
    . sysuse auto
    .
    regress price mpg
    ~~~~~~~
    */


    qui log c
    markdoc example, export(tex) texmaster style(stata) replace


    Anything that is placed between ~~~~~~~ is considered as code block and is printed as is {verbatim} in LaTeX, which preserves the white space and print it in mono-space font. In this example, I also added the texmaster style(stata)which generate the LaTeX file in Stata journal style and also, create the main LaTeX (addding the main required packages) file so that your code can be executable. This is the output of the code (attached). If that was not your question, please be a bit more precise.


    Click image for larger version

Name:	image_3113.png
Views:	1
Size:	30.3 KB
ID:	1310202
    Last edited by haghish; 17 Sep 2015, 11:04.
    ——————————————
    E. F. Haghish, IMBI, University of Freiburg
    [email protected]
    http://www.haghish.com/

    Comment


    • #3
      Hi,

      Thanks for your answer. I'm interested in the latter part of your answer:

      I just want to include the commands, and ignore the outputs as I'm interested in simply getting a LaTeX version of my do-file, incl. its markup. However, using the quietly prefix with quietly { ...} suppresses the commands. The second solution you suggested removes the markup and only includes verbatim code in LaTex.

      I've now found a solution using listings in LaTeX (I'm adding the link below), and I've "stolen" your list of functions and commands from your synlightlist.ado to expand upon this code.

      This solution works for me but I thought this could still be a great addition to MarkDoc. Thanks for all your work on this,

      Andy
      latex: stata language/style definition for listings package

      Comment


      • #4
        Yet another markdown approach you could use is to run things through R's knitr() function. You can do this with the click of a button in the RStudio interface, which makes it pretty painless. knitr() would easily give you the code without the output, even for Stata. The downside of R markdown for Stata is that each code block is a separate Stata session.

        Some notes at http://www.ssc.wisc.edu/~hemken/Stat...own/Stata.html
        Doug Hemken
        SSCC, Univ. of Wisc.-Madison

        Comment


        • #5
          I have no idea what markdoc is, but it sounds as though part of your answer is cmdlog; type
          Code:
          h cmdlog
          at Stata's command line (interactive) prompt

          Comment


          • #6
            Alright! I programmed an additional marker which is /***/ and when you place it before a command, it will execute it, show the outputs in the Stata results window, but removes all the outputs generated by that command in MarkDoc.

            However, this feature will not be available until the next release of MarkDoc. In case you want to give it a try, I attach the markdoc.ado version 3.4 here. Replace this file with your current version and give /***/ a try! Make sure you are using the latest version of MarkDoc which is currently 3.3. Here is an example that should generate exactly the same document I posted before.

            qui log using example, replace

            /***/ sysuse auto
            /***/ regress price mpg


            qui log c
            markdoc example, export(tex) texmaster style(state) replace
            Attached Files
            Last edited by haghish; 17 Sep 2015, 17:10.
            ——————————————
            E. F. Haghish, IMBI, University of Freiburg
            [email protected]
            http://www.haghish.com/

            Comment


            • #7
              Thank you very much!

              Comment


              • #8
                Dear Haghish,

                Thanks again for your support.

                I wanted to quickly ask whether, in MarkDoc, it is possible to use loops when graphs are created and inserted into a .tex document. From your example, it looks like

                ![explain the graph](./graph.png)

                can only be inserted manually, line by line. Is there a way to, say, create and save a histogram for all variables in a foreach loop and add the resulting png files to my .tex document?

                Many thanks for your help,

                Andy

                Comment


                • #9
                  Andy dB You're welcome!

                  Let me begin with saying that the examples I have written in this page ARE NO LONGER WORKING DUE TO SYNTAX CHANGE IN MARKDOC 3.5. I say this for those who might read the page later...

                  Back to your question, there is a txt command in the package (requires installing weaver package i.e. ssc install weaver) which writes dynamic text. For example, you can write:

                  . txt "![explain the graph](./graph.png)"

                  The command can also be used in loops, programs, etc!


                  ——————————————
                  E. F. Haghish, IMBI, University of Freiburg
                  [email protected]
                  http://www.haghish.com/

                  Comment


                  • #10
                    Thank you! I've got this to work, but only if the only thing in the loop is the graph(s). I'm trying the below - but the resulting .tex doesn't show much. I've created the respective .png files in a separate loop, before. Any thoughts what I'm doing wrong here?

                    Code:
                    set linesize 80
                         cap: log close
                         qui log using example, replace
                    
                    * Write the report as a loop
                    
                    foreach n of varlist ca_1  {
                    
                        * Show the value labels
                        txt "labellist `n'"    
                    
                        * Summary statistics, by status
                       txt "tabstat `n', by(schoolstatus) stat(mean sd min max median)"
                    
                        * Summary statistics, by grade
                        txt "tabstat `n', by(grade) stat(mean sd min max median)"
                    
                        txt "![explain the graph](`n'.png)"
                    }
                    
                    qui log c
                    
                    markdoc example, replace export(tex)
                    I've also tried the following, which just never finishes the MarkDoc command in the last line

                    Code:
                    set linesize 80
                         cap: log close
                         qui log using example, replace
                    
                    * Create what will be included in the report; generate combined graphs
                    
                    foreach n of varlist ca_1  {
                    
                        * Show the value labels
                        /**/ labellist `n'    
                    
                        * Summary statistics, by school type
                        /**/ tabstat `n', by(schoolstatus) stat(mean sd min max median)
                    
                        * Summary statistics, by grade
                        /**/ tabstat `n', by(grade) stat(mean sd min max median)
                    
                        txt "![explain the graph](`n'.png)"
                    }
                    
                    qui log c
                    
                    markdoc example, replace export(tex)
                    Last edited by Andy dB; 12 Jan 2016, 10:38.

                    Comment


                    • #11
                      Andy dB

                      Your first example is not relevant, because txt is very similar to display command, but used for printing text, scalars, and macros in the dynamic document. So, you cannot expect it to execute a command...

                      The second example, however, revealed a bug in the txt command. Thank you! The bug appears only when you use txt several times in a row, like in a loop. I have fixed it and will update it in the next Weaver release. For now, I also attach it here so you can get your work done.

                      Here is an example of using the txt command, just to make it clear. The example used Markdown and will create an executable LaTeX document.


                      qui log using example, replace

                      sysuse auto, clear
                      foreach var of varlist price mpg {
                      qui hist `var'
                      qui graph export "`var'.png", width(400) replace
                      txt "![Histogram of the `var' variable](`var'.png)"
                      }

                      qui log c

                      markdoc example, replace exp(tex) texmaster
                      Attached Files
                      ——————————————
                      E. F. Haghish, IMBI, University of Freiburg
                      [email protected]
                      http://www.haghish.com/

                      Comment


                      • #12
                        Thank you very much. That works. I think there is another minor bug: when you loop over two variables n, using

                        Code:
                        /**/ labellist `n'
                        , the first output is shown within verbatim, the second isn't - however, the problem disappears when I write some text with txt, within the loop, before labellist. This is what I want to do anyways, so it doesn't matter. Still, I hope this helps.

                        Thanks again!

                        Comment


                        • #13
                          Andy dB

                          Andy I have a very different perspective here. I don't like the idea of "hiding" a command in a loop, when the rest of the loop is preserved in the document. This can be rather miss-leading. Besides, if you look at the SMCL log-file, you will see that Stata treats the log-file differently when there is a loop (also when a program is written interactively). In the current version, there is no possibility for hiding a loop while preserving the output. But the whole loop and its output can be hidden as shown below. This is something I can develop for the next release.


                          //OFF

                          foreach var of varlist ... {
                          ...
                          ...
                          }

                          //ON


                          ——————————————
                          E. F. Haghish, IMBI, University of Freiburg
                          [email protected]
                          http://www.haghish.com/

                          Comment


                          • #14
                            Thanks for this, haghish ! I have a separate question on MarkDoc: What is the recommended way to include additional packages in the texfile's preamble?

                            I'm trying to create a full tex file that can be compiled straight out of Stata. I can think of several ways but I'm not sure.
                            1. Does MarkDoc have such an option for its texmaster?
                            2. Write a new style, or modify the "simple" style in the adofile?
                            3. If not, write a tex file using the file command (if that is possible) and input the result of MarkDoc (without the texmaster option)?
                            4. Write a tex file yet with another command and input the result of MarkDoc (without the texmaster option)?
                            So far, I've tried

                            Code:
                            set linesize 80
                            cap: log close
                            qui log using report, replace
                            
                            /***
                            \documentclass[10pt,letter]{article}
                            
                            \usepackage{amsmath}
                            \usepackage{setspace}
                            \onehalfspacing
                            \usepackage{amssymb}
                            \usepackage{multicol}
                            \usepackage{graphicx}
                            \usepackage[hidelinks]{hyperref}
                            \usepackage{booktabs, multicol, multirow}
                            \usepackage{fullpage}
                            \usepackage{lscape}
                            \usepackage{placeins}
                            \usepackage{booktabs}
                            \usepackage{longtable,tabu}
                            \usepackage{threeparttablex}
                            \usepackage[usenames,dvipsnames]{color}
                            \usepackage[latin1]{inputenc}
                            
                            \begin{document}
                            {\setlength{\parindent}{0cm}    
                                
                            \title{Some report}
                            \author{The author}
                            \date{January 22, 2016}
                            
                            \maketitle
                            \noindent
                            
                            \tableofcontents
                            
                            \clearpage
                            
                            \section{A section}
                            \subsection{A subsection}
                            \input{tests.txt}
                            \FloatBarrier
                            
                            \end{document}
                            ***/
                            
                            qui log c
                            
                            markdoc report, replace erase export(tex)
                            But this results in the following output

                            Code:
                            \textbackslash{}documentclass{[}10pt,letter{]}\{article\}
                            
                            \usepackage{amsmath} \usepackage{setspace} \onehalfspacing
                            \usepackage{amssymb} \usepackage{multicol} \usepackage{graphicx}
                            \usepackage[hidelinks]{hyperref}
                            \usepackage{booktabs, multicol, multirow} \usepackage{fullpage}
                            \usepackage{lscape} \usepackage{placeins} \usepackage{booktabs}
                            \usepackage{longtable,tabu} \usepackage{threeparttablex}
                            \usepackage[usenames,dvipsnames]{color} \usepackage[latin1]{inputenc}
                            
                            \textbackslash{}begin\{document\} \{\setlength{\parindent}{0cm}
                            
                            \title{Some report}
                            
                            \author{The author}
                            
                            \date{January 22, 2016}\maketitle
                            
                            \noindent
                            
                            \tableofcontents
                            
                            \clearpage
                            
                            \section{A section}
                            
                            \subsection{A subsection}
                            
                            \input{tests.txt} \FloatBarrier
                            
                            \textbackslash{}end\{document\}

                            Thanks again for your help!
                            Last edited by Andy dB; 22 Jan 2016, 18:04.

                            Comment


                            • #15
                              Rich Goldstein suggested that you take a look at:
                              Code:
                              help cmdlog
                              Have you had a look? In which way does it not meet your needs?

                              Svend

                              Comment

                              Working...
                              X