Is it possible to change the way Maxima generates LaTeX code? - styles

I would like to be able to change the way Maxima generates the LaTeX code (in general). For example, I have the following code in Maxima:
I then exported the code to LaTeX, and I immediately get an error saying:
! Package inputenc Error: Unicode char \u8:− not set up for use with LaTeX.
See the inputenc package documentation for explanation.
Type H <return> for immediate help.
You can check out the LaTeX code generated through this gist on GitHub.
I would like at least not only to not get any errors, but also to change a little bit the style of the LaTeX code generation to adapt it to certain circumstances. For example, I would like to be able to insert a break line (or more) after the outputs...
Is it possible to do? Are there any alternatives?

You can put the following line in the preamble of the LaTeX output:
\DeclareUnicodeCharacter{2212}{-}
which tells LaTeX what to do with the Unicode hyphen (character 2212 according to this table).
WxMaxima should generate this declaration itself -- it is a bug that it does not.

Most likely something happened when you exported the code. To fix the existing file you can follow the accepted answer to this question.
https://tex.stackexchange.com/questions/83440/inputenc-error-unicode-char-u8-not-set-up-for-use-with-latex
But try exporting again and see if the error was accidental.
Update:
Add
\DeclareUnicodeCharacter{00A0}{ }
to your preamble.

Well, the gistfile1.txt at line 54 contains − characters instead of -. I wonder how those characters were generated. What commands did you enter in wxMaxima to generate gistfile1.txt?
Anyway, I find that if I replace those characters with ordinary hyphens, it avoids the error you reported. So perhaps the problem is to avoid generating those characters in the first place.
EDIT: This answer is off the mark. See my other answer for a real solution.

Related

Recognise #define compiler directive in fortran with ctags

I would like to configure ctags to recognize compiler directives in a fortran code. More specifically, I would like to match the following vim search result
/\v[ \t]*#define[ \t]+([-[:alnum:]*+!_:\/.?]+)/
where \v induces the very magic level (see Can I turn on extended regular expressions support in Vim?). Alternatively, the search using a normal regular expression
/[ \t]*#define[ \t][ \t]*\([-[:alnum:]*+!_:\/.?][-[:alnum:]*+!_:\/.?]*\)/
could be used. If general compiler directives are found, that would help me too. A practical application would be that when pressing <C+]>, when having my cursor at _ABORT in the following piece of code
_ABORT("delta_time is too small")
I would be redirected to the corresponding definition
#define _ABORT(msg) call abimem_abort(msg, __FILE__, __LINE__)
Based on https://andrew.stwrt.ca/posts/vim-ctags/, I tried to add either
--regex-fortran=/[ \t]*#define[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/d,directives/
or
--regex-fortran=/[ \t]*#define[ \t][ \t]*\([-[:alnum:]*+!_:\/.?][-[:alnum:]*+!_:\/.?]*\)/\1/d,directives/
to ~/.ctags. Based on http://ctags.sourceforge.net/ctags.html, I also tried to add --line-directives=yes, but in neither case I could succeed in the practical application I gave as an example above. I can already see the additional kind when using
ctags --list-kinds
but that's all. What went wrong?
It seems that it works now. My current ~/.ctags is
--fortran-kinds=+i
--recurse=yes
--exclude=.git
--regex-fortran=/[ \t]*#define[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/d,directives/
Probably this has to do with the fact that I previously had put a '\v' in the ~/.ctags (and did not copied this properly to the question). Could someone explain why this '\v' must not be present there, though vim is configured to need it for extended regex's?
Another thing that happened between previous try and now is a reboot (clean-up of temporary space etc.), which might help if still stuck.
Moreover, one should remark that the extra regex is not always necessary. Following macro definition was found without the regex:
# define MSG_ERROR(msg) call libpaw_msg_hndl(msg,"ERROR" ,"PERS")

What does the comment "COMBAK" mean?

I was looking at the vimscript syntax file in the syntax directory, and under the keyword vimTodo were the words COMBAK, FIXME, TODO, and XXX. I can figure out what FIXME and TODO mean pretty easily, and I can guess what some might use XXX for, but I have no idea what COMBAK is for.
It must have a meaning of some sort, else there would be no reason to highlight it. I get that it's a code tag, but what does it mean? My best guess so far is an abbreviation for COMEBACK, though I doubt this.
Here is what I found so far:
Googling it got me nothing of use, and a google code search for COMBAK (with or without the quotes) got 0 results. I eventually Googled codetag "COMBAK" and found a single result, which uses it as a tag in a comment twice (a [ctrl+F] will find it): http://pastebin.com/H6mjbyBh.
The program is written in Vimscript, and contains both a vimscript syntax file and vimscript indent plugin file for lisp, along with some other massive functions.
Yes, it literally means "COME BACK".

Converting header or text file information to code using Linux/Vim

I found myself writing a really simple conversion from OpenCL error codes to a human readable string. The 50 or so different codes are defined in a header file like this:
...
#define CL_INVALID_CONTEXT -34
#define CL_INVALID_QUEUE_PROPERTIES -35
#define CL_INVALID_COMMAND_QUEUE -36
#define CL_INVALID_HOST_PTR -37
...
I put all of these in a huge switch/case using expert copy/pasting:
...
case CL_INVALID_CONTEXT:
return "CL_INVALID_CONTEXT";
case CL_INVALID_QUEUE_PROPERTIES:
return "CL_INVALID_QUEUE_PROPERTIES";
case CL_INVALID_COMMAND_QUEUE:
return "CL_INVALID_COMMAND_QUEUE";
case CL_INVALID_HOST_PTR:
return "CL_INVALID_HOST_PTR";
...
Since I've recently started to use Vim, I am thinking there might be a way to do this in a more efficient way using Linux command tools and Vim. There was a similar post here where someone claimed to have done it with Emacs. Any ideas on how to avoid wasting 15 minutes with a similar task next time?
(I know that oclErrorSting() might exist but let's disregard that for generality's sake!)
You can do this in Vim with a search and replace:
%s/#define \(\w\+\).*/case \1:^M return "\1";/g
The trick to getting the ^M in the output is to type CTRL-V and then Enter where you want put a newline in the output.
This will do the replacement on the entire file.
This works by doing a seach which matches the entire line and replacing it with your desired text. Each name is captured into a group in the search, that's what the \(\w\+\) is doing, then the matched text is used twice in the replacement.
The other generic solution for repetitive tasks is to use macros, or complex repeats are they are called in help.
Basically you start recording your inputs in a register, create a single case, and then go to the next line of your define.
See :help q for more details.

Vim snipMate LaTeX template

I am using Vim to write my LaTeX files, and figured I'd make a few snippets to help me along. It's been no problem writing simple snippets (like one for begin, one for figure etc.), but then when I tried making one to set the title (with a default value including some curly brackets ({and }), I have this problem. The goal of my snippet is that it creates the following text:
\title{My name\\\texttt{me#email.com}}
I want all the text inside the outmost curly brackets (the ones belonging to title) to be a placeholder. I try to accomplish this by writing the snippet as follows:
\title{${1:My name\\\texttt{me#email.com}}}${2}
My problem, however, is that snipMate seems to use only the name and the email (omitting the closing bracket for the texttt command) as a placeholder.
SnipMate has some known problems with these things, the parsing for nested
braces just doesn't work. Maybe someone knows how to do this, but in the
meantime I suggest you creating two snippets, one for \title and another for
\texttt — just to simplify things a bit.
snippet \ti
\title{${1:My name}}
snippet \te
\texttt{${1:me#email.com}}

Changing text appearence in vim

Suppose I have a file, whose entire contents is:
\u1234
and suppose 1234 is the code for \alpha
is there a way to, in vim, have the "\1234" show up as a single \alpha symbol (and be treated as an \alpha symbol) ?
Thanks!
[This problem arises since I want to to use unicode names in g++]
I really don't think this is possible, since vim is designed to present and edit the actual contents of a file (it is not a WYSIWIG editor). I wouldn't recommend it for the exact same reasons, even if you find a way to do it - it will lead to confusion in the future (once you forget the feature, or if it is triggered in a document you weren't expecting, or the script contains a bug, etc.)
There is a plugin for Vim to display certain characters in Haskell as the Unicode symbol: http://www.vim.org/scripts/script.php?script_id=2603.
It even decodes the symbols to their text-representation before writing (and vice versa after reading a Haskell file).
I guess you can do the same, just inspect the plugin's source.
One thing you could do is define custom highlighting so that you know that that character maps to something else. May not be exactly what you want but as soulmerge points out anything else may be dangerous/unclear.

Resources