JunoLab / Weave.jl

Scientific reports/literate programming for Julia
http://weavejl.mpastell.com
MIT License
823 stars 94 forks source link

[BUG] MethodError: no method matching latexinline(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Symbol) #406

Open liuwa666 opened 3 years ago

liuwa666 commented 3 years ago

description

image

using Weave

open("finalreport.jmd", "w") do io
  truncate(io, 0);
  for line in eachline("./data/0.jmd")
    write(io, line, "\n")
  end
  for line in eachline("./data/sec4.jmd")
    write(io, line, "\n")
  end
end

weave("finalreport.jmd"; doctype = "md2pdf", template = "main.tpl", latex_cmd = ["xelatex"])

The last line of code produced the error:

MethodError: no method matching latexinline(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Symbol)
Closest candidates are:
  latexinline(::IO, !Matched::Markdown.LaTeX) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Markdown\src\IPython\IPython.jl:31
  latexinline(::IO, !Matched::Markdown.Code) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Markdown\src\render\latex.jl:42
  latexinline(::IO, !Matched::Array{T,1} where T) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Markdown\src\render\latex.jl:109
  ...
latex(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Markdown.Paragraph) at latex.jl:50
latex(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Array{Any,1}) at latex.jl:23
latex(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Markdown.MD) at latex.jl:19
sprint(::Function, ::Markdown.MD; context::Nothing, sizehint::Int64) at io.jl:105
sprint at io.jl:101 [inlined]
latex at latex.jl:170 [inlined]
clear_buffer_and_format!(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Base.GenericIOBuffer{Array{UInt8,1}}, ::typeof(Markdown.latex)) at common.jl:141
render_chunk(::Weave.WeaveLaTeX2PDF, ::Weave.DocChunk) at texformats.jl:28
_broadcast_getindex_evalf at broadcast.jl:648 [inlined]
_broadcast_getindex at broadcast.jl:621 [inlined]
getindex at broadcast.jl:575 [inlined]
macro expansion at broadcast.jl:932 [inlined]
macro expansion at simdloop.jl:77 [inlined]
copyto! at broadcast.jl:931 [inlined]
copyto! at broadcast.jl:886 [inlined]
copy at broadcast.jl:862 [inlined]
materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Nothing,typeof(Weave.render_chunk),Tuple{Base.RefValue{Weave.WeaveLaTeX2PDF},Array{Weave.WeaveChunk,1}}}) at broadcast.jl:837
render_doc(::Weave.WeaveDoc) at rendering.jl:22
weave(::String; doctype::String, informat::Nothing, out_path::Symbol, args::Dict{Any,Any}, mod::Nothing, fig_path::Nothing, fig_ext::Nothing, cache_path::String, cache::Symbol, template::String, css::Nothing, highlight_theme::Nothing, pandoc_options::Array{String,1}, latex_cmd::Array{String,1}, keep_unicode::Bool) at Weave.jl:223
(::Weave.var"#weave##kw")(::NamedTuple{(:doctype, :template, :latex_cmd),Tuple{String,String,Array{String,1}}}, ::typeof(weave), ::String) at Weave.jl:143
top-level scope at build_latex.jl:31

versions

using InteractiveUtils; versioninfo():


Julia Version 1.5.2
Commit 539f3ce943 (2020-09-23 23:17 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
Environment:
JULIA_EDITOR = "C:\Users\liuwa\AppData\Local\atom\app-1.52.0\atom.exe"  -a
JULIA_NUM_THREADS = 4

> `using Pkg; Pkg.status()`:
<!-- please paste the the output of `using Pkg; Pkg.status()` in the backticks below -->
```julia
Status `C:\Users\liuwa\.julia\environments\v1.5\Project.toml`
  [c52e3926] Atom v0.12.25
  [a93c6f00] DataFrames v0.21.8
  [0c46a032] DifferentialEquations v6.15.0
  [587475ba] Flux v0.11.1
  [916415d5] Images v0.23.1
  [a93385a2] JuliaDB v0.13.0
  [e5e0dc1b] Juno v0.8.4
  [a15396b6] OnlineStats v1.5.7
  [429524aa] Optim v0.20.1
  [91a5bcdd] Plots v0.28.4
  [c3e4b0f8] Pluto v0.12.7
  [44d3d7a6] Weave v0.10.6

main.tpl

\documentclass[UTF8, zihao = -4, heading = true, scheme = chinese, a4paper]{ctexart}
\ctexset{
}
\usepackage{geometry}
\geometry{left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm}
\linespread{1.5}

% \usepackage[a4paper,text={16.5cm,25.2cm},centering]{geometry}
% \usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{bm}
{{#:tex_deps}}
{{{ :tex_deps }}}
{{/:tex_deps}}
% \setlength{\parindent}{0pt}
% \setlength{\parskip}{1.2ex}

% \usepackage{microtype}
% 引入makecell方便嵌套表格
\usepackage{makecell}
% 引入三线表
\usepackage{booktabs}
% 表格中支持跨行
\usepackage{multirow}

% 跨页表格
\usepackage{longtable}

% 固定宽度的表格
\usepackage{tabularx}

% 表格中的反斜线
\usepackage{diagbox}

% 确定浮动对象的位置,可以使用 H,强制将浮动对象放到这里(可能效果很差)
\usepackage{float}

% 定理类环境宏包
\usepackage[amsmath,thmmarks,hyperref]{ntheorem}

\usepackage{graphicx}
% 定义所有的图片文件在 figures 子目录下
% \graphicspath{{fig/}}

% hyperref 宏包在最后调用
\usepackage{hyperref}

\hypersetup
       {   pdfauthor = { {{{:author}}} },
           pdftitle={ {{{:title}}} },
           colorlinks=TRUE,
           linkcolor=black,
           citecolor=blue,
           urlcolor=blue
       }

{{#:title}}
\title{ {{{ :title }}} }
{{/:title}}

{{#:author}}
\author{ {{{ :author }}} }
{{/:author}}

{{#:date}}
\date{ {{{ :date }}} }
{{/:date}}

{{ :highlight }}

\begin{document}

{{#:title}}\maketitle{{/:title}}
\newpage
\tableofcontents
\newpage
{{{ :body }}}

\end{document}

0.jmd

---
title : 技术模块开发
author : 六娃
date : `j import Dates; Dates.Date(Dates.now())`
---
```julia,  echo = false, results = "hidden"
### 正文中不能输入中文双引号和破折号
### 表格中不能输入下划线
### 公式中输入中文请用\text{}或\mbox{}
function print_latex_table(table, caption, label, width)
  println("\\begin{table}[htbp]
  \\small
  \\centering
  \\caption{$caption}
  \\begin{tabularx}$width
  \\toprule ")
  for i = 1:size(table, 1)
    for j = 1:size(table, 2)
      if i !== 1 && i !== size(table, 1)
        if j !== size(table, 2)
            print("$(table[i, j]) & ")
        else
            println("$(table[i, j]) \\\\")
        end
      elseif i ===size(table, 1)
        if j !== size(table, 2)
            print("$(table[i, j]) & ")
        else
            println("$(table[i, j]) \\\\ \\midrule")
        end
      else
        if j !== size(table, 2)
            print("\\bfseries{$(table[i, j])} & ")
        else
            println("\\bfseries{$(table[i, j])} \\\\ \\bottomrule")
        end
      end
    end
  end
  println("\\end{tabularx}
  \\label{$label}
  \\end{table}")
end
function print_latex_table_v1(table, caption, label)
  println("\\begin{table}[htbp]
  \\small
  \\centering
  \\caption{$caption}
  \\begin{tabularx}{\\textwidth}{*{$(size(table, 2))}{>{\\centering\\arraybackslash}X}}
  \\hline ")
  for i = 1:size(table, 1)
    for j = 1:size(table, 2)
      if i !== 1 && i !== size(table, 1)
        if j !== size(table, 2)
            print("$(table[i, j]) & ")
        else
            println("$(table[i, j]) \\\\")
        end
      elseif i ===size(table, 1)
        if j !== size(table, 2)
            print("$(table[i, j]) & ")
        else
            println("$(table[i, j]) \\\\ \\hline")
        end
      else
        if j !== size(table, 2)
            print("\\bfseries{$(table[i, j])} & ")
        else
            println("\\bfseries{$(table[i, j])} \\\\ \\hline")
        end
      end
    end
  end
  println("\\end{tabularx}
  \\label{$label}
  \\end{table}")
end
function print_latex_figure(figure, caption, label, width)
  println("\\begin{figure}[htbp]
  \\centering
  \\includegraphics[width=$width]{$figure}
  \\caption{$caption}
  \\label{$label}
  \\end{figure}")
end

## part of sec4.jmd

```md
##### 构建权重集
根据层次分析法构建权重集。本系统中,权重集$A$分为五层。
(1)第一层次的权重集
$$
\begin{equation}
A_1=\left( a_1, a_2, a_3 \right)
\end{equation}
$$
其中,$a_1$为基础理论的权重,$a_2$为实际训练的权重,$a_3$为训练风貌的权重。

(2)第二层次的权重集
$$
\begin{equation}
A_2=\left( a_{21}, a_{22}, a_{23} \right)
\end{equation}
$$
其中,$a_{21}$为训练水平的权重,$a_{22}$为排故能力的权重,$a_{23}$为参数控制品质的权重。

minimum reproducible steps

johnabs commented 2 years ago

I'm also seeing this bug on a fresh install of Weave for Julia 1.6.3