all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Two short questions about calc
@ 2020-09-07 23:08 Michael Heerdegen
  2020-09-08  2:26 ` Stefan Monnier
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Michael Heerdegen @ 2020-09-07 23:08 UTC (permalink / raw)
  To: Emacs mailing list

Hi,

I've now decided to learn a bit more about Calc so I can use it as my
daily calculator.  Now I have these two questions:

(1) In my init file I set calc-symbolic-mode -> t and calc-prefer-frac >
t because I prefer that most of the time.  Because, hey, I can always
use N to see the numeric value.  But eh - no, actually, this doesn't
work if the result can be interpreted as a fraction.  Even if I convert
a natural number of milliseconds to min+s, calc presents me the result
as a fraction (of course the denominator is not a power of ten most of
the time), and N doesn't work then, I must use another command to get
the numerical value of the fraction.  That, well, is that a question?
It's annoying.  Don't want to need to remember two commands for the same
task.  Why isn't there a command that just gives me the numerical value
of ... anything?

(2) I have also configured Calc to use big mode for output.  There is
also a mode for tex output.  If we already have tex, could we not just
... tex that and insert the picture into the output buffer?  I'm sure
that would break something, but it would be cool I guess (and waste less
space).  Somebody has tried this?  A key to toggle picture vs. normal
output would be nice to have.


Thanks,

Michael.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Two short questions about calc
  2020-09-07 23:08 Two short questions about calc Michael Heerdegen
@ 2020-09-08  2:26 ` Stefan Monnier
  2020-09-30 23:52   ` Michael Heerdegen
  2020-09-08  7:52 ` tomas
  2020-10-09  2:00 ` Another question about Calc (was: Two short questions about calc) Michael Heerdegen
  2 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2020-09-08  2:26 UTC (permalink / raw)
  To: help-gnu-emacs

Hi Michael,

> It's annoying.  Don't want to need to remember two commands for the same
> task.  Why isn't there a command that just gives me the numerical value
> of ... anything?
[...]
> also a mode for tex output.  If we already have tex, could we not just
> ... tex that and insert the picture into the output buffer?  I'm sure

Hmm... is it me, or you forgot to attach the patch to your message?


        Stefan




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Two short questions about calc
  2020-09-07 23:08 Two short questions about calc Michael Heerdegen
  2020-09-08  2:26 ` Stefan Monnier
@ 2020-09-08  7:52 ` tomas
  2020-09-11 21:13   ` Michael Heerdegen
  2020-10-09  2:00 ` Another question about Calc (was: Two short questions about calc) Michael Heerdegen
  2 siblings, 1 reply; 10+ messages in thread
From: tomas @ 2020-09-08  7:52 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 735 bytes --]

On Tue, Sep 08, 2020 at 01:08:33AM +0200, Michael Heerdegen wrote:
> Hi,
> 
> I've now decided to learn a bit more about Calc so I can use it as my
> daily calculator.  Now I have these two questions:
> 
> (1) In my init file I set calc-symbolic-mode -> t and calc-prefer-frac >
> t because I prefer that most of the time.

This cribbed from the Calc manual:

   The ‘c f’ (‘calc-float’) [‘pfloat’] command converts the number
   on the top of the stack to floating-point form.  For example,
   ‘23’ is converted to ‘23.0’, ‘3:2’ is converted to ‘1.5’, and
   ‘2.3’ is left the same.

...if you don't mind losing precision. If you do, then (1) was a trick
question ;-)

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Two short questions about calc
  2020-09-08  7:52 ` tomas
@ 2020-09-11 21:13   ` Michael Heerdegen
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Heerdegen @ 2020-09-11 21:13 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs

<tomas@tuxteam.de> writes:

> ...if you don't mind losing precision. If you do, then (1) was a trick
> question ;-)

No, I didn't intend to ask a trick question.  Maybe I'm just a tiny bit
disappointed that I have to remember two different key bindings.

I think the trick for me to use is: write input as decimals dot zero
when I don't want Calc to compute symbolically.

Michael.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Two short questions about calc
  2020-09-08  2:26 ` Stefan Monnier
@ 2020-09-30 23:52   ` Michael Heerdegen
  2020-10-01  3:31     ` Stefan Monnier
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Heerdegen @ 2020-09-30 23:52 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

Hi Stefan Monnier,

> > also a mode for tex output.  If we already have tex, could we not just
> > ... tex that and insert the picture into the output buffer?  I'm sure
>
> Hmm... is it me, or you forgot to attach the patch to your message?

No, it's you.

Ok - I tried to find anything reusable to do the latex => image part.
Auctex didn't really fit (and I didn't like the coding in preview.el),
so I guess org preview stuff could help to make the image.  And then I
found I can use Calc output filter stuff to change the display text
property to show the image instead.  That works, basically, but it's not
that nice:

#+begin_src emacs-lisp
  (require 'calc-lang)
  ;; (calc-set-language 'big nil 'no-refresh)
  (progn
    (calc-set-language 'latex nil 'no-refresh)
    (defun my-latex-output-filter (s)
      (let (prefix latex-string file-string)
        (if (string-match "\\([ ]+\\)\\(.+\\)" s)
            (setq prefix (match-string 1 s)
                  latex-string (match-string 2 s))
          (setq prefix "" latex-string s))
        (setq file-string
              (with-temp-buffer
                (insert (concat "$" latex-string "$\n"))
                (cl-letf (((plist-get org-format-latex-options :scale) 1.7))
                  (org-format-latex "/tmp/ltximg/org-ltximg"
                                    (point-min) (copy-marker (point-max))
                                    "/tmp/" nil nil 'forbuffer 'dvipng))
                (goto-char (point-min))
                (if (search-forward-regexp "\\[\\[file:\\(.*\\)\\]\\]" nil t)
                    (match-string 1)
                  nil)))
        (concat prefix (if file-string
                           (propertize latex-string 'display
                                       (create-image file-string 'png nil :mask 'heuristic))
                         latex-string))))

    (put 'latex 'math-output-filter 'my-latex-output-filter))
#+end_src

I works - most of the time -- sometimes I get "image has not been
created, check this and that" messages, I didn't yet investigate.  The
good part is, Calc commands don't seem to interfere at all with this
hack.  That's where I expected the real problems.  Once it really works,
I would make it a separate language of course, "latexed-latex",
probably.


Regards,

Michael.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Two short questions about calc
  2020-09-30 23:52   ` Michael Heerdegen
@ 2020-10-01  3:31     ` Stefan Monnier
  2020-10-01  3:41       ` Michael Heerdegen
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2020-10-01  3:31 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

>> > also a mode for tex output.  If we already have tex, could we not just
>> > ... tex that and insert the picture into the output buffer?  I'm sure
>> Hmm... is it me, or you forgot to attach the patch to your message?
> No, it's you.

;-)

> I works - most of the time -- sometimes I get "image has not been
> created, check this and that" messages, I didn't yet investigate.  The
> good part is, Calc commands don't seem to interfere at all with this
> hack.  That's where I expected the real problems.  Once it really works,
> I would make it a separate language of course, "latexed-latex",
> probably.

Cool!  Looks promising,


        Stefan




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Two short questions about calc
  2020-10-01  3:31     ` Stefan Monnier
@ 2020-10-01  3:41       ` Michael Heerdegen
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Heerdegen @ 2020-10-01  3:41 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Cool!  Looks promising,

Yes.  And the error I sometimes got was only because of the newlines in
the latex input I think (so surrounding in $...$ then just doesn't
work, one needs to use an environment afaik).  I don't know yet if we
want to have actual line breaks in the output image because we don't
exactly know how large the final image will be.

Michael.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Another question about Calc (was: Two short questions about calc)
  2020-09-07 23:08 Two short questions about calc Michael Heerdegen
  2020-09-08  2:26 ` Stefan Monnier
  2020-09-08  7:52 ` tomas
@ 2020-10-09  2:00 ` Michael Heerdegen
  2020-10-09 13:19   ` Another question about Calc Stefan Monnier
  2 siblings, 1 reply; 10+ messages in thread
From: Michael Heerdegen @ 2020-10-09  2:00 UTC (permalink / raw)
  To: Emacs mailing list

Hello,

when I change the language to LaTex in Calc (d L), then

  ' 1 + 1 / 2

==> 1

I.e. the expression is interpreted as (1 + 1) / 2 contrarily to the
mathematical convention.

I know Latex a bit, but never heard that it calculates...like that.  Is
this behavior expected?  Does it make sense in some way?


Thanks,

Michael.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Another question about Calc
  2020-10-09  2:00 ` Another question about Calc (was: Two short questions about calc) Michael Heerdegen
@ 2020-10-09 13:19   ` Stefan Monnier
  2020-10-10  6:39     ` Michael Heerdegen
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2020-10-09 13:19 UTC (permalink / raw)
  To: help-gnu-emacs

> I know Latex a bit, but never heard that it calculates...like that.

AFAIK LaTeX doesn't calculate at all.  I don't see any evidence that it
treats `A + B / C` as having any kind of internal structure.

AFAICT it adjusts the spacing between the five elements only based on
"lexical" rather than "syntactical" information.

In the places where LaTeX does calculate (e.g. in lengths) it seems not
to support division and only support "multiplication by concatenation"
which makes multiplication bind more tightly than addition?

> Is this behavior expected?  Does it make sense in some way?

I think the fact that the syntax is inspired by LaTeX doesn't give
us much guidance on how precedence should be handled.

So from where I stand, this looks like a bug.


        Stefan




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Another question about Calc
  2020-10-09 13:19   ` Another question about Calc Stefan Monnier
@ 2020-10-10  6:39     ` Michael Heerdegen
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Heerdegen @ 2020-10-10  6:39 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> AFAIK LaTeX doesn't calculate at all.  I don't see any evidence that it
> treats `A + B / C` as having any kind of internal structure.

AFAIR it has macros to perform calculations, but then the input is not
given as latex formatted formula.

> > Is this behavior expected?  Does it make sense in some way?
>
> I think the fact that the syntax is inspired by LaTeX doesn't give
> us much guidance on how precedence should be handled.
>
> So from where I stand, this looks like a bug.

That's what I think, too.  I'll create a report.

Thanks,

Michael




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-10-10  6:39 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-07 23:08 Two short questions about calc Michael Heerdegen
2020-09-08  2:26 ` Stefan Monnier
2020-09-30 23:52   ` Michael Heerdegen
2020-10-01  3:31     ` Stefan Monnier
2020-10-01  3:41       ` Michael Heerdegen
2020-09-08  7:52 ` tomas
2020-09-11 21:13   ` Michael Heerdegen
2020-10-09  2:00 ` Another question about Calc (was: Two short questions about calc) Michael Heerdegen
2020-10-09 13:19   ` Another question about Calc Stefan Monnier
2020-10-10  6:39     ` Michael Heerdegen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.