找回密码
 快速注册
搜索
查看: 1055|回复: 14

[tikz]\begin{tikzpicture}\draw plot(\x,sin(\x r));\end{tikzpicture}[/tikz]

[复制链接]

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2021-11-16 16:53 |阅读模式
要把图放到标题上,得用尽可能短的 tikz 代码画尽可能复杂的图

830

主题

4862

回帖

3万

积分

积分
36159

显示全部楼层

isee 发表于 2021-11-16 18:53
过分了啊~~~~

830

主题

4862

回帖

3万

积分

积分
36159

显示全部楼层

isee 发表于 2021-11-16 18:56
不对,着魔了啊~

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

 楼主| kuing 发表于 2021-11-17 16:24
改变方法之后外面的标题变不了图了,算啦我也玩够了

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2021-12-26 16:19
本帖最后由 hbghlyj 于 2022-6-21 15:55 编辑

用Node.js搞了一个应用程序,它可以把你发送的tex文档用pdflatex/xelatex/...转换为pdf,然后用pdf2svg转换为svg,再发给你,并且缓存最近30天的所有图片,例如
  1. window.open("http://tex.cjhb.site?tex="+encodeURIComponent("\\documentclass[10pt,crop,tikz]{standalone}\\usepackage{tikz-cd}\\usepackage{amsmath}\\usepackage{amsfonts}\\usepackage{mathrsfs}\\begin{document}\\begin{tikzpicture}\\draw[gray, thick] (-1,2) -- (2,-4);\\draw[gray, thick] (-1,-1) -- (2,2);\\filldraw(0,0) circle (2pt) node[anchor=west]{Intersection point};\\end{tikzpicture}\\end{document}"))
复制代码

  1. window.open("http://tex.cjhb.site?tex="+encodeURIComponent("\\documentclass[10pt,crop,tikz]{standalone}\\usepackage{tikz-cd}\\usepackage{amsmath}\\usepackage{amsfonts}\\usepackage{mathrsfs}\\begin{document}\\begin{tikzpicture}[>=latex,line width=1pt,x=4cm,y=4cm] \\draw[->] (-1.5,0)--(1.5,0) node[right] {$x$}; \\draw[->] (0,-1.5) node[below=10pt] {$\\displaystyle S=\\frac{12}{5}\\arctan\\left[\\sqrt{265+118 \\sqrt{5}-2 \\sqrt{30\\left(1165+521 \\sqrt{5}\\right)}}\\,\\right]-\\frac{3 \\sqrt{15}}{160}$} --(0,1.5) node[above] {$y$}; \\filldraw[draw=red,fill=red!50,fill opacity=0.5] (1,0) \\foreach \\i in {0,...,4} { -- plot[domain={\\i*144}:{\\i*144+144},smooth] ({3/5*cos(\\x)+2/5*cos(3*\\x/2)},{3/5*sin(\\x)-2/5*sin(3*\\x/2)}) }; \\node[red,below left] at (-0.8,-0.6) {$\\left\\{\\begin{aligned} x&=\\frac35\\cos(t)+\\frac25\\cos\\left(\\frac{3t}{2}\\right)\\\\ y&=\\frac35\\sin(t)-\\frac25\\sin\\left(\\frac{3t}{2}\\right) \\end{aligned}\\right.$}; \\fill[blue] ({(1+sqrt(5))/16},{(1+sqrt(5))/16*tan(pi/5 r)}) circle (2pt) node[above right] {$\\displaystyle \\left(\\frac{1+\\sqrt5}{16}, \\frac{1+\\sqrt5}{16}\\tan\\frac\\pi5\\right)$}; \\end{tikzpicture}\\end{document}"))
复制代码

此外,参数"engine"的缺省值是pdflatex,它还可以选择xelatex(比如需要使用pstricks时),也可以为lualatex(比如需要tikzlibrary graphdrawing时).
lualatex示例:
  1. window.open("http://tex.cjhb.site?engine=lualatex&tex="+encodeURIComponent('\\documentclass{standalone} \\usepackage{tikz}\\usetikzlibrary{graphdrawing} \\usetikzlibrary{graphs} \\usegdlibrary{trees} \\begin{document} \\begin{tikzpicture}[>=stealth, every node/.style={circle, draw, minimum size=0.75cm}] \\graph [tree layout, grow=down, fresh nodes, level distance=0.5in, sibling distance=0.5in] { 4 -> { 3 -> { 1 -> { 5, " " }, 2,2 }, 3 -> { 1, 2, 2 }, 3 -> { 1, 2, 2 } } }; \\end{tikzpicture} \\end{document}'))
复制代码

xelatex示例:
  1. window.open("http://tex.cjhb.site?engine=xelatex&tex="+encodeURIComponent('\\documentclass[12pt,pstricks,border=15pt]{standalone}\n\\usepackage{pstricks}\n\\begin{document}\n\\def\\myFig{\n \\pscustom[fillstyle=solid,fillcolor=yellow,opacity=.5]{%\n \\psarcn(3,0){3}{180}{90}\\psarcn(1,3){2}{0}{-90}\n \\psarc(1,2){1}{-90}{0}\\psarc(2,0){2}{90}{180}\n }\n \\pscustom[fillstyle=solid,fillcolor=blue,opacity=.5]{%\n \\psarc(0,3){3}{-90}{0}\\psarcn(1,3){2}{0}{-90}\n \\psarcn(2,1){1}{180}{90}\\psarc(2,0){2}{90}{180}\n \\closepath\n }\n}\n\n\\begin{pspicture}(0,0)(6,6)\n\\rput(0,3){\\myFig}\n\\rput{-270}(6,3){\\myFig}\n\\rput{180}(6,3){\\myFig}\n\\rput{-90}(0,3){\\myFig}\n\\end{pspicture}\n\\end{document}'))
复制代码

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

 楼主| kuing 发表于 2021-12-27 00:04
回复 5# hbghlyj

只能说,你TQL

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

 楼主| kuing 发表于 2021-12-30 12:43
回复 10# hbghlyj


    图都挂了

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2022-1-1 05:33
回复 11# kuing
抱歉...我刚调试好...现在应该好了吧

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

 楼主| kuing 发表于 2022-1-1 11:40
回复 12# hbghlyj

奶思

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2022-1-10 23:02
今天用asymptote画图的时候一直报错,后来搜到是因为opacity与ghostscript的"安全模式"不兼容,把-nosafe这个选项加上就可以了,见:tex.stackexchange.com/questions/473893/error-in-asymptote-using-upacity-to-draw-a-lemniscate

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2022-1-11 00:38
本帖最后由 hbghlyj 于 2022-1-11 01:31 编辑 现在虽然不报错了,但是无法设置透明度(opacity)
  1. fill( box((2cm,3cm), (3cm,4cm)), opacity(0.5)+red);fill( box((3cm,3cm), (4cm,4cm)), red);
复制代码
正常来讲,左边的颜色较浅,但是我这里颜色一样
在官网上运行的结果:
我的PC版Asymptote的运行结果:
我的环境:
Asymptote version 2.70
Windows 10, x86-64

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2022-1-11 01:04
另外,当我在PC版asymptote设置输出格式为svg时,只出现左边的正方形,且透明度未丢失,显示错误:
  1. 桌面>asy -f svg temp.asy
复制代码
ERROR: error in special: '>' expected at end of closing tag </g

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2022-1-11 01:33
本帖最后由 hbghlyj 于 2024-3-2 20:44 编辑 现已解决svg的故障,原先asy使用png现改为svg,16楼的透明度丢失的问题就不存在了.
size(5cm);
fill(box((2cm,3cm), (3cm,4cm)), opacity(0.5)+red);fill( box((3cm,3cm), (4cm,4cm)), red);

解决办法是加上
  1. --libgs=""
复制代码
这个选项
参见github.com/vectorgraphics/asymptote/issues/33
代码已更新,见附件

运行npm build就可以使用了.
调试时,先挂上那个asy.js,用ssh登进去,然后
  1. node dist/main.js
复制代码
用http,在3000端口调试

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2022-1-13 10:19
本帖最后由 hbghlyj 于 2022-1-13 11:29 编辑 用asymptote画抛物柱面$z=x^2$ 下载.png
  1. size(6cm);
  2. import graph3;
  3. currentprojection =
  4. orthographic(1,1.5,0.2);
  5. real f(pair xy) {
  6. real x = xy.x; real y = xy.y;
  7. return x^2;
  8. }
  9. surface s = surface(f, (-1.5,-1), (1.5,1));
  10. draw(s,surfacepen=white,meshpen=black,nolight);
  11. xaxis3("$x$",-2,2,red,Arrow3);
  12. yaxis3("$y$",-2,2,green,Arrow3);
  13. zaxis3("$z$",-1,2,blue,Arrow3);
复制代码
用pgfplots画一个类似的图(参考) y x z
  1. \documentclass{standalone}
  2. \usepackage{pgfplots}
  3. \begin{document}
  4. \begin{tikzpicture}
  5. \begin{axis}[view={120}{20},xmin=-2,xmax=2,ymin=-2,ymax=2,zmin=0,zmax=2,axis lines=none]
  6. \addplot3[surf,domain=-1.2:0,y domain=-1:1,mesh,draw=black,samples=5,samples y=8]{x^2};
  7. \addplot3[surf,domain=0:1.2,y domain=-1:1,surf,faceted color=black,fill=white,samples=5,samples y=8]{x^2};
  8. \end{axis}
  9. \end{tikzpicture}
  10. \end{document}
复制代码
箭头(坐标轴)是后期用boxy svg加的.
用pgfplots画一个圆锥面$z=\sqrt{x^2+y^2}$ z x y
用pgfplots画一个双曲抛物面(马鞍面): x y z
  1. \documentclass{standalone}
  2. \usepackage{pgfplots}
  3. \pgfplotsset{ticks=none}
  4. \begin{document}
  5. \begin{tikzpicture}
  6. \begin{axis}[view={35}{25},xmin=-2,xmax=2,ymin=-2,ymax=2,axis lines = center, axis on top, axis line style = {thick, red!80!black}]
  7. \addplot3[surf,domain=-1:1,y domain=-1:1,surf,faceted color=black,fill=white,samples=15,samples y=15]{x^2-y^2};
  8. \end{axis}
  9. \end{tikzpicture}
  10. \end{document}
复制代码

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2022-6-21 23:00
更新一下代码:
把node和tex的故障信息都放入log.如果没有svg输出,就输出log.
把原先的if...else多层嵌套改为switch(原先的代码太难看了....)
https支持.
把asymptote独立出来了.放在另一个帖子中.

$type tex.zip (3.99 KB, 下载次数: 0)

手机版|悠闲数学娱乐论坛(第3版)

GMT+8, 2025-3-4 12:08

Powered by Discuz!

× 快速回复 返回顶部 返回列表