Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: =?UTF-8?Q?J=c3=b6rg_Buchholz?= Newsgroups: comp.graphics.apps.gnuplot Subject: Re: space between sign and digit Date: Thu, 12 Jul 2018 07:36:03 +0200 Organization: A noiseless patient Spider Lines: 37 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Thu, 12 Jul 2018 05:36:01 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="fd6a019edca8e8dd90db4588a1c2874e"; logging-data="24004"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18bePBoMib9ZXRtF65qHxgEWlKlw8Wve68=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 Cancel-Lock: sha1:ZJXauVQZm6E72UbAIE9GZj3jAYg= In-Reply-To: Content-Language: en-GB Xref: csiph.com comp.graphics.apps.gnuplot:4003 On 11.07.2018 15:16, Karl Ratzsch wrote: > Am 11.07.2018 um 14:16 schrieb Jörg Buchholz: >> On 11.07.2018 10:00, Karl Ratzsch wrote: >>> plot f11(x) lt 2 lw 4 dt 4 t \ >>> sprintf("f11(x) =%.2f·x %s %.2f",a,b11<0?"-":"+",abs(b11)) >>> >> >> Interesting solution. On more complex functions the code is a bit long. > > You're welcome. ;-) This looks a bit nicer > > nstr(x) = sprintf("%s %.2f",x<0?"-":"+",abs(x)) # return string with a > space between sign and number > > plot f11(x) title sprintf("f11(x) =%.2f·x %s",a,nstr(b11)) > > or you can even outsource the whole sprintf() call into a function > > tstr(n,a,b) = sprintf("%s = %.2f·x %s %.2f",n,a,b<0?"-":"+",abs(b)) > > plot f11(x) title tstr("f11(x)",a,b11) > > so your plot command stays readable. It is the right direction, something like a "newcommand" in LaTex that makes the daily work easier. But I need the %.2f variable, cause sometimes there are numbers which needs more or less digits after the floating point. At the moment I keep at the long version. Thanks for helping. Jörg