Announcement

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

  • #16
    Thank you, I no longer get a Markdoc error message. But I get the tex error !Undefined control sequence from the Stata output if I change directory when I use the style stata. I use updated Stata 14.2 and markdoc 3.8.7 from GitHub on Windows 7.

    For example if I add cd "C:/temp" as here:

    Code:
    cd "C:/temp"
    qui log using example, replace
    
    /***
    This is a Markdown Heading
    ==========================
    
    This is a Markdown subheading
    -----------------------------
    
    This is a text paragraph. 
    ***/
    
    cd ..
    cd "C:/temp"
    
    qui log c
        
    markdoc example, replace title("How to write text in MarkDoc") ///
        export(tex) toc master style("stata") noisily
    Then the tex console output is
    Code:
    ! Undefined control sequence.
    l.35       C:\temp
    There is no error if I instead use the style("simple"). The error is only with style("stata").

    As an aside, the style("stata") adds a first page titled "THE STATA JOURNAL" with a linkable subtitle "How to write text in MarkDoc .................... Short article author list" and with page number 1. I am not sure if there are other large differences between the two styles (apart from the error in the stata style) but this one seems worth mentioning.

    Comment


    • #17
      I have narrowed down the problem I reported in #16 to be related to the *TeX stlog environment. I am using MikTex 2.9.

      When the export format is tex, the stata style uses the stlog environment whereas the simple style uses the verbatim environment.

      Despite the problem, I find MarkDoc to be a great user-written improvement to Stata's capabilities for literate programming (e.g., sjlatex and sjlog). Haghish's Rcall has a different purpose but is also great! MarkDoc is similar to R's Markdown. R is investing heavily in Markdown, and the latest effort is known as Bookdown. The bookdown package is mentioned as highlight in the newly released RStudio v1.0. It has even been reported that the word for "log" in R is Markdown :-)

      Comment


      • #18
        I have narrowed down further the cause of the problem as reported in #16. The executing pandoc command is

        Code:
        "c:\ado\plus\Weaver\pandoc\pandoc.exe" --mathjax --toc  "example.md" -o "C:\Users\AALEXA~1\AppData\Loca
        > l\Temp\ST_2g000001.tmp.tex"
        The tex file has this code:

        Code:
        \section{This is a Markdown Heading}\label{this-is-a-markdown-heading}
        
        \subsection{This is a Markdown
        subheading}\label{this-is-a-markdown-subheading}
        
        This is a text paragraph.
        
        \begin{verbatim}
        . cd ..
        C:\
        
        . cd "C:/temp"
        C:\temp
        
        
        \end{verbatim}
        The tex file from the last command outputs C:\temp but it should be either C:\\temp (i.e., have two backslashes) or C:/temp (i.e., have one forward slash). I can manually edit the tex file to make it run correctly. Unfortunately, set trace on does not get saved in the log file, so troubleshooting and fixing markdoc itself is difficult.

        Comment


        • #19
          Anders Alexandersson

          producing dynamic document for Stata Journal was one of those ideas that if I go back in time probably I wouldn't do, and instead keep the things simple, basic, and general.

          that said I didn't have any problem with this on Mac. But at least we both agree your problem is happening in stlog and not the default style. Which means, it's not MarkDoc's bug, because it only uses stlog instead of verbatim for putting Stata commands and output in one of these environments.
          ——————————————
          E. F. Haghish, IMBI, University of Freiburg
          [email protected]
          http://www.haghish.com/

          Comment


          • #20
            For people new to this thread, the current issue is this LaTeX code in Windows for the stata style:
            Code:
            cd c:/temp
            haghish
            Thank you. I sympathize with the programming difficulty. But the idea of a separate LaTeX style for the Stata Journal is great. RStudio has implemented custom styles for R, as illustrated here. Notably missing in the R Markdown custom formats is a style for the Stata Journal. But that omission is probably because of marketing rather than technical difficulties, I bet, since RStudio has reasons to promote R rather than Stata. I am not sure if the Windows stata style problem to change directory is in the stlog environment and therefore outside of MarkDoc, as you argue. It should be possible to confirm with code. The instructions "Getting Started with the Stata Journal" refer to sjlatex.

            Can Windows users of sjlatex change directory with cd c:/temp? If yes, then the bug seems to be in MarkDoc. If no, then the bug instead seems to be with the stlog environment in sjlatex. I have only used sjlatex one time in 2004 but can try to test it if needed.
            Last edited by Anders Alexandersson; 18 Nov 2016, 12:45. Reason: Added cd c:/temp in the bolded sentence since that is the only specific problem I tested.

            Comment


            • #21
              Anders MarkDoc also allows you to apply your own style. See the image below. And thanks for being enthusiastic about MarkDoc, it means a lot to me. I appreciate your effort for debugging the software as well. Please keep on trying to figure out what is going wrong with Windows and Stata Journal style. As I said, I had no issue with this on Mac. By the way, you can fork the repository on GitHub and if you figure out where the bug is, just push it and I will accept your changes.

              https://github.com/haghish/MarkDoc

              Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	28.6 KB
ID:	1364811


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

              Comment


              • #22
                haghish Thanks for encouraging me to try to fix the stata style bug in Windows, and for telling about user-defined styles. I can use change directory with valid tex output using the stlog environment in sjlog but not in markdoc. Therefore the problem is in markdoc, not in stlog.

                ​​​​​​​In LaTeX, sjlatex outputs a forward slash with two backslashes whereas MarkDoc wrongly outputs it with only one backslash. I followed the instructions at http://www.ats.ucla.edu/stat/stata/latex/verbatim.htm . Here is my Stata code I used for testing sjlog (and sjlatex):

                Code:
                sjlog using test_stlog
                pwd
                cd c:/temp
                pwd
                cd c:/sjtemp
                pwd
                sjlog close
                sjlog type test_stlog.log.tex
                Here is my working LaTeX code (as copied and pasted following the above instructions):
                Code:
                \documentclass[11pt]{article}
                \usepackage{stata}
                \begin{document}
                \section{Example 1}
                \begin{stlog}
                
                . pwd
                c:\\sjtemp
                {\smallskip}
                . cd c:/temp
                c:\\temp
                {\smallskip}
                . pwd
                c:\\temp
                {\smallskip}
                . cd c:/sjtemp
                c:\\sjtemp
                {\smallskip}
                . pwd
                c:\\sjtemp
                {\smallskip}
                
                \end{stlog}
                \end{document}
                For MarkDoc, a quick workaround is to use the notation marker /***/ in the do-file to include the command but exclude the output. Another quick workaround is to add manually the missing second backslash in the tex-file to get valid tex code. I will not post again about this unless I fix the bug.

                Comment


                • #23
                  Thanks for this.

                  It is clear that sjlog is not identical to verbatim environment. So basically, the Stata command cannot be included in the document as is. I will fix this in the future updates. Not sure whether I keep Stata Journal style, I have second thought that perhaps using another general layout would be better.
                  ——————————————
                  E. F. Haghish, IMBI, University of Freiburg
                  [email protected]
                  http://www.haghish.com/

                  Comment


                  • #24
                    haghish I'm breaking my promise to not post unless I have a bug fix in the hope that you will keep the Stata Journal style despite the bug. Just call it a feature limitation instead of a bug. This is not so different from the previous bug of not handling invalid UTF-8. Basically, it is a small bug but the style is still useful. Eventually, you or I or StataCorp or someone else will find a fix.

                    It is clear that sjlog is not identical to verbatim environment.
                    Yes, see
                    Code:
                    viewsource sjlog.ado
                    for the actual code. It does lots of file path manipulation for TeX which is the general issue here.

                    So basically, the Stata command cannot be included in the document as is.
                    Yes, the Stata log file needs to be converted to include TeX macros by using the sjlog command to get a true Stata Journal style. This is explained in Section "2.3 Stata output" on pages 6-8 in main.pdf which you get when you install sjlatex. There is a similar user-written command dotex (SSC) which may or may not be helpful.

                    Comment


                    • #25
                      Well that was very helpful, indeed. So basically the sjlog.ado prepares the document for Stata Journal? And all we have to do is to call sjlog program before hand? I never used sjlog program before. But I will look into it.
                      ——————————————
                      E. F. Haghish, IMBI, University of Freiburg
                      [email protected]
                      http://www.haghish.com/

                      Comment


                      • #26
                        Yes, basically the sjlog.ado prepares the document for Stata Journal. In addition to calling sjlog before the code, you also need to sjlog close, replace afterwards. It is very straightforward and well explained in main.pdf. It is nothing new. For example, there is a 2008 Statalist posting about this.


                        As shown on page 6 in main.pdf, this is the actual code used if the tex file from sjlog is output1.log.tex:
                        Code:
                        \begin{stlog}
                        \input{output1.log.tex}\nullskip
                        \end{stlog}
                        I think you will find it helpful to look also at main.tex which is the tex file that creates main.pdf. The file main.tex calls sj.tex and stata.tex and it is stata.tex that actually has the tex code above you are interested in.

                        Comment


                        • #27
                          The bug with Stata Journal style is fixed. thanks for the bug report.
                          ——————————————
                          E. F. Haghish, IMBI, University of Freiburg
                          [email protected]
                          http://www.haghish.com/

                          Comment


                          • #28
                            haghish Thank you. I am now using the new MarkDoc version 3.91 on Windows 7.

                            Unfortunately, the bugfix with Stata Journal style introduced a more serious problem of allowing only one comment for Windows users. Here is example code for calling the do-file:

                            Code:
                             markdoc "F:\DOH\tmp_28nov.do" , markup(markdown) export(tex) replace statax ///
                                 style("stata") master toc noisily
                            Here is my new minimal do-file code:

                            Code:
                            /**/ qui log using example, replace
                            
                            /***
                            Part A.
                            ***/
                            
                            /***
                            Part B.
                            ***/
                            
                            qui log c
                            The code fails as is. But the code works if I remove either the "Part A" comment of the "Part B" comment. Here is the full output:
                            Code:
                            .  markdoc "F:\DOH\tmp_28nov.do" , markup(markdown) export(tex) replace statax ///
                            >      style("stata") master toc noisily 
                            
                            
                            Pandoc path
                            
                            
                            . /**/ qui log using example, replace
                            
                            . 
                            . 
                            . 
                            . //OFF
                            . tempfile results
                            
                            . tempname resread reswrite 
                            
                            . file open `reswrite' using "`results'", write replace
                            (note: file C:\Users\AALEXA~1\AppData\Local\Temp\ST_1v000008.tmp not found)
                            
                            . file open `resread' using "C:\Users\AALEXA~1\AppData\Local\Temp\ST_1v000005.tmp", read
                            
                            . file read `resread' line
                            
                            . while r(eof) == 0 {
                              2.   file write  `reswrite' `"`macval(line)' "'
                              3.   local test : display real("`line'")
                              4.   if "`test'" != "."{
                              5.       file write  `reswrite' "`test'"
                              6.   }
                              7.   else {
                              8.     local test2 //RESET
                              9.     local test3 //RESET
                             10.     capture local test2 : display `line'
                             11.     capture local test3 : display int(`test2')
                             12. 
                            .     if !missing("`test2'") & "`test3'" == "`test2'" {
                             13.         capture local m : display `line'
                             14.         if _rc == 0 {
                             15.            file write  `reswrite' "`m'"
                             16.         }
                             17.     }
                             18.     else if !missing("`test3'") & "`test3'" != "`test2'" {
                             19.         capture local m : display %10.2f `line'
                             20.         if _rc == 0 {
                             21.            file write  `reswrite' "`m'"
                             22.         }
                             23.         else {
                             24.         capture local m :  display "`line'"
                             25.          file write  `reswrite' "`m'"
                             26.         }
                             27.     }
                             28.     else if !missing("`test2'") & missing("`test3'") {
                             29.         capture local m : display %10.2f `line'
                             30.         if _rc == 0 {
                             31.            file write  `reswrite' "`m'"
                             32.         }
                             33.     }
                             34.     if missing("`test2'")  {
                             35.         capture local m : display  "`line'"
                             36.         file write  `reswrite' "`m'"
                             37.     }
                             38. }
                             39.   file read `resread' line
                             40.   file write  `reswrite'   _n
                             41. }
                            
                            . file close `resread' 
                            
                            . file close  `reswrite' 
                            
                            . quietly copy `results' C:\Users\AALEXA~1\AppData\Local\Temp\ST_1v000007.tmp, public rep
                            > lace
                            
                            . //ON
                            . 
                            end of do-file
                            
                            . /***
                            > Part A.
                            > ***/
                            . 
                            end of do-file
                            file C:\Users\AALEXA~1\AppData\Local\Temp\ST_1v000004.tmp cannot be modified or erased;
                                likely cause is read-only directory or file
                            r(608);
                            
                            end of do-file
                            
                            r(608);
                            The directory "C:\Users\aalexandersson" and its subfolders and files are read-only. But, according to my sysadmin, this is how it should be and the permission settings have not been changed recently. Also, I tried running Stata as Administrator but it did not solve the new problem. Again, the new problem appears in Windows and only if I have two comments, and the problem did not exist before the bugfix of the directory backslash.

                            Finally, I have a small feature wish: a multi-line address or a separate option for "city, state/country" such as "Miami, FL" or "Freiburg, Germany".

                            Comment


                            • #29
                              THanks for the bug report.
                              1. I have no error running your code on Mac
                              2. the process was changed to add a new feature in MarkDoc, a convenient method for writing dynamic text: https://github.com/haghish/MarkDoc/wiki/Dynamic-text
                              3. please upload a full smcl log file to inspect it. From what you posted, it is not very clear what's going wrong.
                              ——————————————
                              E. F. Haghish, IMBI, University of Freiburg
                              [email protected]
                              http://www.haghish.com/

                              Comment


                              • #30
                                please upload a full smcl log file to inspect it. From what you posted, it is not very clear what's going wrong.
                                I am still using the new MarkDoc version 3.9.1 (not 3.91 as I wrongly wrote) on Windows 7.

                                I have now removed the "quiet" part and I have added a command before and after the two comments to possibly easier see what is going on. The code for calling the new do-file is the same:
                                Code:
                                 markdoc "F:\DOH\tmp_28nov.do" , markup(markdown) export(tex) replace statax ///
                                     style("stata") master toc noisily
                                This is the new do-file:
                                Code:
                                log using example, replace
                                
                                sysuse auto, clear
                                
                                /***
                                Part A.
                                ***/
                                
                                describe
                                
                                /***
                                Part B.
                                ***/
                                
                                di "hello world"
                                
                                
                                log c
                                The do-file ends with the error after the first "Part A" comment, just like I reported. Therefore, I had to manually close the log file. As requested, a full smcl log file is attached.
                                Attached Files

                                Comment

                                Working...
                                X