Forgot password?
 Create new account
View 875|Reply 143

Asymptote测试

[Copy link]

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

hbghlyj Posted at 2022-6-3 10:15:55 |Read mode
Last edited by hbghlyj at 2025-3-2 15:10:00


Asymptote代码:

701

Threads

110K

Posts

910K

Credits

Credits
94145
QQ

Show all posts

kuing Posted at 2023-1-10 19:58:03
Last edited by hbghlyj at 2025-3-24 02:32:52

Comment

好啊  Posted at 2023-1-10 19:58

701

Threads

110K

Posts

910K

Credits

Credits
94145
QQ

Show all posts

kuing Posted at 2023-1-10 23:49:21
  1. <script>
  2. let asys = document.getElementsByTagName('asy');
  3. for (let item of asys) {
  4.         //item.innerHTML=item.innerHTML.replace(/&nbsp;/g,' ');
  5.         //var str = item.innerText;
  6.         var str = item.textContent;
  7.         console.log(str);
  8.         //var str = item.innerHTML.replace(/<br>/g, "").replace(/&nbsp;/g,' ').replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
  9.         var str_for_show = encodeURI(str).replace(/\'/g,'’');
  10.         var str_for_link = encodeURIComponent(str);
  11.         item.innerHTML = '<img src="https://kuing.cjhb.site/asy/?code='+str_for_link+'" onclick="show_tikz_window(\''+str_for_show+'\');" />';
  12. }
  13. </script>
Copy the Code

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2023-1-10 23:52:14
kuing 发表于 2023-1-10 16:49
let asys = document.getElementsByTagName('asy');
for (let item of asys) {
        var str = item.innerHTML ...
我觉得
  1. var str = item.innerHTML.replace(/<br>/g, "").replace(/&nbsp;/g,' ');
Copy the Code
可以用innerText或textContent写成
  1. var str = item.innerText;
Copy the Code

Comment

哦  Posted at 2023-1-11 00:04

701

Threads

110K

Posts

910K

Credits

Credits
94145
QQ

Show all posts

kuing Posted at 2023-1-11 00:47:20
hbghlyj 发表于 2023-1-10 23:52
我觉得可以用innerText或textContent写成
&nbsp; 还是有必要替换掉的,否则转换后它会变成 %C2%A0 ,从而在图中会产生真的空格。

test:



(《Asymptote 范例教程》里的例子)

Comment

哦  Posted at 2023-1-11 00:56

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2023-1-28 18:34:26
@kuing

用同样的方法利用mpppreview可以使论坛支持metapost
同样地, 发送一个post请求, mpsource参数是代码😃

Comment

不搞了😌  Posted at 2023-1-28 22:38

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2023-4-19 19:31:42
hbghlyj 发表于 2023-1-10 16:52
我觉得可以用innerText或textContent写成
使用textContent的优点是保留换行\n😀
若使用innerText则\n都会变成空格,导致代码中的单行注释把后面所有行都注释了

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2023-4-19 19:36:03
kuing.cjhb.site/kk/zdy3pc.js
  1.     item.innerHTML = item.innerHTML.replace(/&nbsp;/g,' ');
  2.     var str = item.textContent;
Copy the Code

这2行应该可以简化为1行吧
  1.     var str = item.textContent.replace(/\\u00a0/g, " ")
Copy the Code

701

Threads

110K

Posts

910K

Credits

Credits
94145
QQ

Show all posts

kuing Posted at 2023-4-19 12:00:31
“挤楼”测试。

看看能否把下面两层(textContent 和 2行简化1行 的建议)给挤下去😉

失败了😌

701

Threads

110K

Posts

910K

Credits

Credits
94145
QQ

Show all posts

kuing Posted at 2023-11-20 15:47:01
貌似挂了,这帖只有 7# 用 format=png 那图能显示,其他都不行,不知为啥。

而 1# 的三个提交,第二个也出错,看来是 svg 不行?

701

Threads

110K

Posts

910K

Credits

Credits
94145
QQ

Show all posts

kuing Posted at 2023-11-21 14:12:16
Last edited by kuing at 2023-11-21 14:21:00
kuing 发表于 2023-11-20 15:47
貌似挂了,这帖只有 7# 用 format=png 那图能显示,其他都不行,不知为啥。

而 1# 的三个提交,第二个也出 ...
不是 svg 不行,而是似乎现在必须指定 format 😳

那尝试将自定义 js 里的其中一行改成
  1. item.innerHTML = '<img src="/asy/?format=svg&code='+str_for_link+'" onclick="show_tikz_window(\''+str_for_show+'\');" />';
Copy the Code


现在是有时行有时不行😳每次刷新都不一定同😳

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-1-31 17:04:00
提個小建議
  1. <a href="javascript:;" class="flbc" style="float:right;margin:3px 6px 0 0;" onclick="close_tikz_window();">
Copy the Code

可簡化為
  1. <a href="javascript:close_tikz_window();" class="flbc" style="float:right;margin:3px 6px 0 0;">
Copy the Code

Comment

明白了😊  Posted at 2024-1-31 17:17

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-2-19 02:04:47
您的第一张图像无法正确显示,我看到完整的SVG代码,但在它之前有一个<b>Warning</b>:  Undefined array key "format" in <b>/home/vol2_6/epizy.com/epiz_31707543/htdocs/asy/index.php</b> on line <b>4</b><br />

这个warning来自哪里? 来自 php 还是来自 Asymptote 服务器

701

Threads

110K

Posts

910K

Credits

Credits
94145
QQ

Show all posts

kuing Posted at 2024-2-19 02:43:48
hbghlyj 发表于 2024-2-19 02:04
您的第一张图像无法正确显示,我看到完整的SVG代码,但在它之前有一个

这个warning来自哪里? 来自 php  ...
我不懂……

看 11#、12#,当时应该是发现必须指定 format 才行,否则报错。
而 2# 的第一个图当时是直接用 [img] 然后贴连接的就没有指定 format ,如下:
  1. [img]https://kuing.cjhb.site/asy/?code=import%20graph%3Bdraw(graph(new%20real(real%20x)%7Breturn%20exp(-x%5E2%2F2)%2Fsqrt(2pi)%3B%7D%2C-5%2C5)%2Cheavyred%2B1)%3B%0Aunitsize(0.8cm%2C4cm)%3B%0Adraw((-5.2%2C-0.05)--(5.2%2C-0.05)--(5.2%2C0.45)--(-5.2%2C0.45)--cycle)%3B%0Afor(int%20i%3D0%3Bi%3C6%3Bi%2B%3D2)%7Blabel(%220.%22%2B(string)i%2C(-5.2%2C0.1i)%2Calign%3DW)%3B%7D%0Afor(int%20i%3D-5%3Bi%3C6%3B%2B%2Bi)%7Blabel((string)i%2C(i%2C-0.05)%2Calign%3DS)%3B%7D%0Alabel(%22%24x%24%22%2C(0%2C-0.15)%2Calign%3DS)%3B%0Alabel(%22%24%5Cmu%3D0%2C%5C%3B%5Csigma%5E2%3D1%24%22%2C(3%2C0.3))%3B[/img]
Copy the Code

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-2-19 02:49:03
也许可以追踪此警告是来自PHP脚本还是Asymptote服务器
在 php 中,只需将 @ 符号附加到函数前面,警告就会被抑制,例如: $contents = @file_get_contents('/path/to/file.html');

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-2-19 02:51:51
我怀疑警告不是来自Asymptote服务器
我怀疑 php 脚本中访问 空参数“format”的行触发警告
所以如果在这一行前面加上@符号,会抑制警告

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-2-19 02:55:12
用同样的方法利用quickchart.io/documentation/graphviz-api/可以使论坛支持GraphViz

701

Threads

110K

Posts

910K

Credits

Credits
94145
QQ

Show all posts

kuing Posted at 2024-2-19 03:00:08
hbghlyj 发表于 2024-2-19 02:51
我怀疑警告不是来自Asymptote服务器
我怀疑 php 脚本中访问 空参数“format”的行触发警告
所以如果在这一 ...
asy/index.php 前几行是:
  1. <?php
  2. if(empty($_GET['format'])){$f='svg';}
  3. //if(empty($_GET['format'])){$f='png';}
  4. if($_GET['format']=='svg'||$_GET['format']=='png'||$_GET['format']=='html') {$f=$_GET['format'];}
  5. $url = "http://asymptote.ualberta.ca:10007?f=".$f;
Copy the Code

我现在将第 4 行改成 elseif,即
  1. <?php
  2. if(empty($_GET['format'])){$f='svg';}
  3. //if(empty($_GET['format'])){$f='png';}
  4. elseif($_GET['format']=='svg'||$_GET['format']=='png'||$_GET['format']=='html') {$f=$_GET['format'];}
  5. $url = "http://asymptote.ualberta.ca:10007?f=".$f;
Copy the Code

现在 2# 图1 好像可以了?

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-2-19 04:34:20
hbghlyj 发表于 2024-2-18 18:55
用同样的方法利用https://quickchart.io/documentation/graphviz-api/可以使论坛支持GraphViz ...
graphviz论坛可以直接在您的帖子中由 DOT 源代码生成 DOT 图表

例如在帖子中写
[dot]digraph {a -> b}[/dot]
然后得到:
a a b b a->b

701

Threads

110K

Posts

910K

Credits

Credits
94145
QQ

Show all posts

kuing Posted at 2024-2-27 19:19:11

手机版Mobile version|Leisure Math Forum

2025-4-20 12:16 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list