haghish / markdoc

A literate programming package for Stata which develops dynamic documents, slides, and help files in various formats
http://haghish.com/markdoc
88 stars 31 forks source link

I do not know if this is the right place to post this so aplogizes in advance if it is not... #18

Closed glennsandstrom closed 6 years ago

glennsandstrom commented 7 years ago

I have worked intensively a couple of days trying to start using markdoc in my workflow but have run into problems with inserting images that I can not get around. I have installed weaver and statax trough ssc and markdoc using:

net install markdoc, force from("https://raw.githubusercontent.com/haghish/markdoc/master/") version is: 3.9.6 Stata SE v.13.1 on Windows 10 Enterprise

Running the example script from: http://www.haghish.com/statistics/stata-blog/reproducible-research/markdoc.php#img /****/ qui log using example, replace smcl

//OFF sysuse auto, clear histogram price //ON

img // that simple!

//OFF histogram mpg graph export mpg.png, replace width(300) //ON

img mpg.png, title("Figure 2. The histogram of the mpg variable")

//or alternatively use Markdown syntax e.g. description

/ _Figure 2_. The histogram of the __mpg__ variable /

txt "_Figure 2_. The histogram of the __mpg__ variable" _n

qui log c markdoc example, export(docx) replace install author("E. F. Haghish") /// title("Importing a graph in MarkDoc") /*****/ results in the error.....

file img.ado not found (error occurred while loading img.ado) r(601); end of do-file r(601); // The ado is installed in my sysdir path C:\ado\plus\i\img.ado and the helpfile is loaded when i run help img running img somefile.png with set trace on the exeqution exit with error //

= if missing("ado") {
  di as err "{p}file extension not recognized; MarkDoc can generate " "dynamic Stata h

elp files from {bf:do}, {bf:ado}, and {bf:mata} files" _n exit 198 }

  • confirm file "`script'" = confirm file "img.ado" file img.ado not found ------------------------------------------------------------------------ end sthlp ---

any help would be greatly appreciated

Best,

Glenn Sandström

aalexandersson commented 7 years ago

Glenn,

I am not sure what the fix is but the troubleshooting syntax is wrong. That is, your syntax img somefile.png is wrong.

The syntax instead should be either img using somefile.png

if you try to import the file somefile.png, or img if you try to include the current graph.

I had no problem with the test script using Stata 14 on Markdoc version 3.8.7. I am not testing 3.9.6. I recommend you to re-run with set trace on (using valid syntax this time).

Anders

On Mon, Feb 20, 2017 at 5:17 AM, Glenn Sandström notifications@github.com wrote:

I have worked intensively a couple of days trying to start using markdoc in my workflow but have run into problems with inserting images that I can not get around. I have installed weaver and statax trough ssc and markdoc using:

net install markdoc, force from("https://raw. githubusercontent.com/haghish/markdoc/master/") version is: 3.9.6 Stata SE v.13.1 on Windows 10 Enterprise

Running the example script from: http://www.haghish.com/ statistics/stata-blog/reproducible-research/markdoc.php#img /*** */ qui log using example, replace smcl

//OFF sysuse auto, clear histogram price //ON

img // that simple!

//OFF histogram mpg graph export mpg.png, replace width(300) //ON

img mpg.png, title("Figure 2. The histogram of the mpg variable")

//or alternatively use Markdown syntax e.g. [image: description] http://filename

/ [image: Figure 2. The histogram of the mpg variable] http://mpg.png /

txt "[image: Figure 2. The histogram of the mpg variable] http://mpg.png" _n

qui log c markdoc example, export(docx) replace install author("E. F. Haghish") /// title("Importing a graph in MarkDoc") /*** **/ results in the error.....

file img.ado not found (error occurred while loading img.ado) r(601); end of do-file r(601); /

/ The ado is installed in my sysdir path C:\ado\plus\i\img.ado and the helpfile is loaded when i run help img running img somefile.png with set trace on the exeqution exit with error //

= if missing("ado") { di as err "{p}file extension not recognized; MarkDoc can generate " "dynamic Stata h

elp files from {bf:do}, {bf:ado}, and {bf:mata} files" _n exit 198 }

  • confirm file "`script'" = confirm file "img.ado" file img.ado not found

    end sthlp ---

any help would be greatly appreciated

Best,

Glenn Sandström

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/haghish/markdoc/issues/18, or mute the thread https://github.com/notifications/unsubscribe-auth/AThPmvCWMifzppbbogRLcbOvhasCMsQiks5reWg6gaJpZM4MF_W4 .

glennsandstrom commented 7 years ago

Thanks for the input. The example code is copy-pasted from the tutorial at http://haghish.com/statistics/stata-blog/reproducible-research/markdoc.php The error is thrown immediately when calling the img command:

. img                                     // that simple! 
file img.ado not found
(error occurred while loading img.ado)

However, I tried removing the current graph part and changed the example to:

qui log using example, replace smcl
//OFF
sysuse auto, clear
histogram mpg
graph export mpg.png, replace width(300)
//ON
img using mpg.png, title("_Figure 2_. The histogram of the __mpg__ variable")
//or alternatively use Markdown syntax e.g.  ![description](filename)
/***
![_Figure 2_. The histogram of the __mpg__ variable](mpg.png)
***/
txt "![_Figure 2_. The histogram of the __mpg__ variable](mpg.png)" _n 
qui log c
markdoc example, export(pdf) replace install author("E. F. Haghish") ///
title("Importing a graph in MarkDoc")

And this results in the same error:

. //ON
. 
. img using mpg.png, title("_Figure 2_. The histogram of the __mpg__ variable")
file img.ado not found
(error occurred while loading img.ado)
r(601);

I have already tried the set trace on and the error is thrown by the sthpl.ado command with the last couple of rows of output being the same as in my previous post:


- confirm file "`script'"
= confirm file "img.ado"
file img.ado not found
------------------------------------------------------------------------ end sthlp ---

So unfortunately I am still at square 1 on this problem.

glennsandstrom commented 7 years ago

Complete output from trace for the code relating to sthlp.ado

 = sthlp img.ado, markup("") export("sthlp") template("") replace  title("") 
> author("") affiliation("") address("") summary("")  version("")  
      ---------------------------------------------------------- begin sthlp ---
      - local version = int(`c(stata_version)')
      = local version = int(13.1)
      - if `version' <= 13 {
      = if 13 <= 13 {
      - local trim trim
      - local version 11
      - }
      - if `version' > 13 {
      = if 11 > 13 {
        local trim ustrltrim
        local version 14
        }
      - version `version'
      = version 11
      - syntax anything(name=script id="The script file name is") [, replace TEM
> Plate(str) Export(name) ASCIItable TITle(str) AUthor(str) AFFiliation(str) ADD
> ress(str) Date SUMmary(str) VERsion(str) build markup(str) helplayout ]
      - if missing("`export'") local export sthlp
      = if missing("sthlp") local export sthlp
      - local input `script'
      = local input img.ado
      - if (index(lower("`input'"),".ado")) {
      = if (index(lower("img.ado"),".ado")) {
      - local name : subinstr local input ".ado" ""
      - local convert "`name'.`export'"
      = local convert "img.sthlp"
      - local extension ado
      - }
      - else if (index(lower("`input'"),".mata")) {
      = else if (index(lower("img.ado"),".mata")) {
        local name : subinstr local input ".mata" ""
        local convert "`name'.`export'"
        local extension mata
        }
      - else if (index(lower("`input'"),".do")) {
      = else if (index(lower("img.ado"),".do")) {
        local name : subinstr local input ".do" ""
        local convert "`name'.`export'"
        local extension do
        }
      - capture confirm file "`script'.ado"
      = capture confirm file "img.ado.ado"
      - if _rc == 0 {
        local name : subinstr local input ".ado" ""
        local convert "`name'.`export'"
        local script `script'.ado
        local extension ado
        }
      - if missing("`extension'") {
      = if missing("ado") {
        di as err "{p}file extension not recognized; MarkDoc can generate " "dyn
> amic Stata help files from {bf:do}, {bf:ado}, and {bf:mata} files" _n
        exit 198
        }
      - confirm file "`script'"
      = confirm file "img.ado"
file img.ado not found
      ------------------------------------------------------------ end sthlp ---
      }
    ------------------------------------------------------------ end markdoc ---
(error occurred while loading img.ado)
r(601);

end of do-file

r(601);
glennsandstrom commented 7 years ago

confirm file "C:\ado\plus\i\img.ado"

works with no errors but

the call made in markdoc->sthlp

confirm file "img.ado"

plausibly because the confirm file call does not supply a complete path to the ado...?

Output from my sysdir command is

PLUS: c:\ado\plus\

aalexandersson commented 7 years ago

Your conclusion seems plausible also to me. So, go ahead and test it :-) That is, temporarily change the current work directory to where img.ado is: cd "C:\ado\plus\i\" If the test script now works, then yes you identified a new bug in version 3.9.6.

Also, does version 3.8.7 work for you? Version 3.8.7 was the most stable for me up until version 3.9.3. Then, I switched to LaTeX and -texdoc- which I now prefer over markdoc so I cannot comment on version 3.9.6.

On Mon, Feb 20, 2017 at 9:24 AM, Glenn Sandström notifications@github.com wrote:

confirm file "C:\ado\plus\i\img.ado"

works with no errors but

the call made in markdoc

confirm file "img.ado"

plausibly because the confirm file call does not supply a complete path to the ado...?

Output from my sysdir command is

PLUS: c:\ado\plus\

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/haghish/markdoc/issues/18#issuecomment-281091985, or mute the thread https://github.com/notifications/unsubscribe-auth/AThPml7Ylr_ewV3GVywiekoFHlv9FSEtks5reaIPgaJpZM4MF_W4 .

glennsandstrom commented 7 years ago

Thanks for the suggestion. Running the script from "C:\ado\plus\i\" improved things in terms of not quitting with the previous error

"(error occurred while loading img.ado) r(601);"

anymore. Now it loads the img.ado as it should but now the windows shellscript looks for the imagefiles e.g. "mpg.png" not in the current working directory (where they are saved) but rather....

Loading pages (1/6)
Warning: Failed to load file:///C:/Users/<my local username>/AppData/Local/Temp/mpg.png (ignore)
[============================================================] 100%

and does not include the images in the produced pdf.

I think I will give up for now and see if I have better luck with a later version of markdoc as I am having no luck with getting this version 3.9.6 to run the example scripts provided in the wiki here on github. Hope you other guys have better luck because it seems to be a great package.

glennsandstrom commented 7 years ago

I have solved the problem. I mixed the installation procedure by using: net install markdoc, replace from("https://raw.githubusercontent.com/haghish/markdoc/master/") for the markdoc installation but used ssc for weaver and statax ssc install weaver ssc install statax

when i replaced weaver and statax by using net install image commands are working properly

net install weaver, replace from("https://raw.githubusercontent.com/haghish/weaver/master/") net install statax, replace from("https://raw.githubusercontent.com/haghish/statax/master/")

...so anyone having problems should make sure that they have used only ssc or only net install from github to ensure compatible versions of all the supporting ado-files.

Sorry for bothering everyone with this stupid mistake.

Best,

Glenn Sandström

roblem commented 7 years ago

Unfortunately, I am seeing the same problems in both Stata 12 (linux) and Stata 15 (windows) using the ssc install method (not mixing github and ssc repos). The only workaround for me was to install all three packages from github as outlined by @glennsandstrom above.

ncvanegmond commented 7 years ago

Unfortunately, I am seeing the similar problems in both Stata 14.2 (Windows)

When I install all packages from the repository:

\\ with this line it works sometimes 
\\ without I always get 'log rundoc not found'
.cd "C:\ado\plus\i\"     
. img
log rundoc not found

Alternatively:

.cd "C:\ado\plus\i\"      \\ adding this line makes no difference
. img mpg.png, title("_Figure 2_. The histogram of the __mpg__ variable")
varlist not allowed

When I install all packages from SSC:

. img                                     // that simple! 
file img.ado not found
(error occurred while loading img.ado)

Alternatively:

.cd "C:\ado\plus\i\"  
.img mpg.png, title("_Figure 2_. The histogram of the __mpg__ variable")
file C:\Users\NielsE\AppData\Local\Temp\ST_03000003.tmp cannot be modified or erased;
    likely cause is read-only directory or file
roblem commented 7 years ago

I can confirm similar issues as reported by @ncvanegmond suffered by multiple students in my class using Stata 14.2 on either Windows or Linux irrespective of how it is installed (ssc or github). Markdoc in Stata 14.2 appears to work fine on a mac however. We have all upgraded to Stata 15......

haghish commented 7 years ago

it seems the last update caused many problems, I will look into that.

smriti-ganapathi commented 6 years ago

I have tried installing weaver and statax from the github link mentioned above, but I get an error saying: "https://raw.githubusercontent.com/haghish/weaver/master/ either 1) is not a valid URL, or 2) could not be contacted, or 3) is not a Stata download site (has no stata.toc file)."

(although I was successful with installing markdoc from the above-mentioned link). I then downloaded the img.ado and added it to my personal directory in the ado files folder, which helped the files run without the error message. However, the pictures still do not appear in the final document.

Additionally, when I use the option export(pdf), I get an error saying that it was unable to convert the html to pdf, although I do have wkhtmltopdf installed (and also tried additionally adding the ado file to my directory, but that didn't work either).

I would be any grateful for any insight as to why this is happening!

Thanks, Smriti

haghish commented 6 years ago

As I am releasing a new version of markdoc, I went through this bug report. the problem is actually caused from an OLD example, from my website. when markdoc was published, Stata journal suggested that the syntax of the img filename - when a path to a file is given - should change to img using filename, which is the usual syntax preferred by Stata (and indeed it looks better).

So, try this updated syntax and it should work just fine. I examined it with Stata 14 and 15 on Win 10 64bit, after a fresh installation of markdoc from Github


// EXAMPLE 
// ===========================================
qui log using example, replace smcl

//OFF
sysuse auto, clear
histogram price
//ON

img // that simple!

//OFF
histogram mpg
graph export mpg.png, replace width(300)
//ON

////// ERROR ONE: img using
img using mpg.png, title("Figure 2. The histogram of the mpg variable")

//or alternatively use Markdown syntax e.g.  description

/***
Figure 2. The histogram of the mpg variable
***/

txt "Figure 2. The histogram of the mpg variable" _n

qui log c
markdoc example, export(docx) replace install author("E. F. Haghish") ///
title("Importing a graph in MarkDoc")
haghish commented 6 years ago

Unfortunately, I am seeing the same problems in both Stata 12 (linux) and Stata 15 (windows) using the ssc install method (not mixing github and ssc repos). The only workaround for me was to install all three packages from github as outlined by @glennsandstrom above.

markdoc has not been updated on SSC for 2 years and is only maintained on Github!