Announcement

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

  • Trouble configuring use of whereis with Word for Mac and markstat in Stata 16

    Hello all,

    I very happily developed a .do file on a Windows 10 machine using markstat with pandoc and Word (and whereis). The code runs the Stata markdown file, then opens the html file in Word for further commentary/notes to be saved by the user.

    I have whereis set up as follows on my computer (Windows 10):
    Code:
    . whereis
    pandoc c:\Program Files\Pandoc\pandoc.exe
    msword C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE
    The code works fine on my machine:
    Code:
    markstat using buildmaps.stmd
    whereis msword
    winexec `r(msword)' /f "buildmaps.html"
    However, my colleague uses a Mac. While I have been able to explain how to configure pandoc with whereis (using which to find the path to the pandoc binary), this has not worked for Word, and searching both on this forum and online in general hasn't turned up a clear answer for me. Any suggestions or tips (especially from someone who has Stata on a Mac, and can verify it works) would be greatly appreciated.

    Thanks,
    Charlene

  • #2
    On my maoOS Catalina system running Stata 16.1 this Stata shell command runs the macOS open command to open a specified document using Microsoft Word
    Code:
    shell open "/Users/lisowskiw/Downloads/Test word document.docx" -a "/Applications/Microsoft Word.app"
    and having opened it, returns control to Stata without waiting for Word to exit.

    The -a option to the macOS open command specifies the application to use. It is not needed if the document is to be opened by the default application associated with the type of the specified document, but since your example suggests you are opening an HTML document in Word, it will probably be necessary.

    I have no familiarity with whereis, but I think you can adapt this syntax to meet your needs by replacing the application path with `r(msword)'.

    Comment


    • #3
      Hi @Charlene Barina. A couple of observations on how -markstat- works

      1. -markstat- uses -whereis- to find the location of pandoc. On my Mac air the location is /usr/local/bin/pandoc. Note the lack of .exe. If I understand
      correctly, this part is working for your colleague on a Mac.

      2. -markstat- then uses Stata's -view browse- command to open the resulting output file. This command relies on file associations in the OS, and will open html files in the browser and docx files in Word. This step does not use -whereis-.

      If I understand correctly what you are doing, you are generating an html file which you then want to open in Word, in which case something along the lines of William Lisowski's advice should work, except that the extension of the target file would be .html rather than .docx. In this case you could use -whereis- to store the location of Word.

      An alternative would be to use -markstat-'s -docx- option to generate a Word document instead of html, which should then open automatically in Word.
      Last edited by German Rodriguez; 10 Aug 2020, 08:11.

      Comment


      • #4
        Hi German Rodriguez , and thanks for your messages in the past as well! I prefer the layout of what is generated when I open the HTML file in Word, versus the docx option, as for the most part the styling from Markdown seems to carry over directly from the HTML better, and it parses the document structure better with Word's navigation pane (it's a pretty complicated output).

        I tried William Lisowski approach first, which worked when done interactively (one line at a time typed) with this:

        Code:
        whereis msword
        shell open "/path-to-file/results.html" -a "`r(msword)'"
        However, when I put it into the script, with a check for the OS, it wasn't working:

        Code:
        global isWindows = 1
        if "`c(os)'" != "Windows" {
            global isWindows = 0
        }
        
        whereis msword
        
        if ${isWindows} {
            winexec `r(msword)' /f "${projpath}/output//${survey}-results.html"
        }
        else {
            shell open "${projpath}/output//${survey}-results.html" -a "`r(msword)'"
        }
        Any thoughts? I still don't have a mac, so I can't easily test it remotely, unfortunately, if it's something simple/obvious.

        Comment


        • #5
          However, when I put it into the script, with a check for the OS, it wasn't working: ... Any thoughts?"
          My thought is that there are dozens of ways any piece of code can "not work" but it's hard to diagnose the problem if we aren't told they symptoms reported by Stata.

          The following code runs as expected opening the html file when run from the Do-file editor window in my copy of Stata 16.1 for Mac.
          Code:
          // set needed global variables not set in example code
          global projpath "/Users/lisowskiw/Downloads"
          global survey Hello
          
          // show my test html file
          ls "${projpath}/output//${survey}-results.html"
          
          // example code from post #4 starts here, coped exactly
          global isWindows = 1
          if "`c(os)'" != "Windows" {
              global isWindows = 0
          }
          
          whereis msword
          
          if ${isWindows} {
              winexec `r(msword)' /f "${projpath}/output//${survey}-results.html"
          }
          else {
              shell open "${projpath}/output//${survey}-results.html" -a "`r(msword)'"
          }
          Code:
          . // set needed global variables not set in example code
          . global projpath /Users/lisowskiw/Downloads
          
          . global survey Hello
          
          .
          . // show my test html file
          . ls ${projpath}/output//${survey}-results.html
          
          -rw-r--r--@ 1 lisowskiw  staff  38668 Sep 22 20:13 /Users/lisowskiw/Downloads/output//Hello-results.html
          
          .
          . // example code from post #4 starts here, coped exactly
          . global isWindows = 1
          
          . if "`c(os)'" != "Windows" {
          .     global isWindows = 0
          . }
          
          .
          . whereis msword
          /Applications/Microsoft Word.app
          
          .
          . if ${isWindows} {
          .     winexec `r(msword)' /f "${projpath}/output//${survey}-results.html"
          . }
          
          . else {
          .     shell open "${projpath}/output//${survey}-results.html" -a "`r(msword)'"
          
          . }
          
          .
          end of do-file
          And at this point the Hello-results.html file is open in Microsoft Word.

          If you meant to tell us that the code in post #4 is not working on Windows, then I expect it could be because the msword registered with whereis shown in post #1 has a space in it, and despite your assertion in post #1 that the code you show worked, I would expect it to require quotation marks around the command name.
          Code:
          winexec "`r(msword)'" /f "${projpath}/output//${survey}-results.html"

          Comment

          Working...
          X