Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex for jumping to section from TOC #192

Open
Konfekt opened this issue Jun 29, 2014 · 7 comments
Open

Regex for jumping to section from TOC #192

Konfekt opened this issue Jun 29, 2014 · 7 comments

Comments

@Konfekt
Copy link

Konfekt commented Jun 29, 2014

Jumping from the TOC to a section whose title contains nested braces does not always work in LatexBox. How about using the following RegEx to spot the section title:

Say we are looking for a \section whose title is the string title. Then, to find the section header, we could use the following regex regex.

regex = '/m' . '\s*\\section' . '/V'.'{'. EscapeString('title').'}'. '/m'.'.*' 

The /m tells Vim to interpret the following regex by the magic syntax, the /V tells Vim to interpret the following regex by the almost literal syntax, only the backslashes need escaping. This is achieved by the EscapeString(string) function.

" Escape special characters in a string for exact matching.
" This is useful to copying strings from the file to the search tool
" Based on this - http://peterodding.com/code/vim/profile/autoload/xolox/escape.vim
function! s:EscapeString (string)
  let string=a:string
  " Escape regex characters
  let string = escape(string, '^$.*\/~[]')
  " Escape the line endings
  let string = substitute(string, '\n', '\\n', 'g')
  return string
endfunction

Edit: Apparently the EscapeString function does not even need the '/V' command to work. So it boils down to

regex = '/m' . '\s*\\section{'.EscapeString('title').'}.*' 
@lervag
Copy link

lervag commented Jun 29, 2014

This is probably part of a solution, yes. However, the problem is slightly more difficult. The reason is that the TOC is based on the aux file, not the tex file. The section titles are parsed from the aux file, and the titles may have been parsed by various packages and similar.

I think the best way to go to make the TOC selections work for complicated section titles is to rewrite the TOC parser, such that it parses the tex file. This requires more work, though, but I might be able to do it some time soon. This should also make the TOC functionality work also when the manuscript has not been compiled.

@Konfekt
Copy link
Author

Konfekt commented Jul 1, 2014

Ok, this I did not know about. Parsing the tex files given by file.tex.latexmain is the safest solution.

In the meanwhile, the section title appearing in the .aux file are not too different from the .tex files. Apparently white spaces are added before ^ at some places.

@lervag
Copy link

lervag commented Jul 3, 2014

Yes, it is important to parse the main tex file. And true, there are whitespaces added before ^. I suspect there may be more changes, but I am not sure.

In any case, I am working on this. There are more challenges, though, such that counting the numers for the section (this is given in the aux file). So the tex file parsing is not straightforward, but I think I will be able to implement it. I am working on this in my own "version" of LaTeX-Box, which you may find here. When I am done I will port it to LaTeX-Box as well. In the mean time, I hope you can live with the less than optimal version of the TOC window as it exists now. Or you can try to add the regex as you propose yourself.

@Konfekt
Copy link
Author

Konfekt commented Jul 4, 2014

Ok, so if 'title' is the literal section title, then the regex regex to be searched for is built in two steps:

First

regex = '\m'.EscapeString(title)

and afterwards

regex = AddHatSpaces(regex)

where AddHatSpaces inserts \? after each occurence of ^.

@Konfekt
Copy link
Author

Konfekt commented Jul 4, 2014

I noticed your LaTeX-Box fork and I would prefer it to LateX-Box itself as it is more minimalist. I am also using Neosnippet and Neocomplete.

Unfortunately, somewhat hidden in the documentation, you mention that your fork dropped Windows support, the OS I am currently using... I think you should put it in the Readme.md.

@lervag
Copy link

lervag commented Jul 4, 2014

Thanks, yes, that would be good to put in the README. Btw: If your willing to assist, then I might consider adding support for windows. The main reason I dropped support is that I do not use windows myself, and so development becomes difficult since I can't test. I don't think it should be that difficult. Most of the code already exist in LaTeX-Box, I only need to find a clever way to make the code well structured.

Edit: If you are interested, then I would appreciate if you could open an issue with vim-latex to continue the discussion.

@lervag
Copy link

lervag commented Jul 9, 2014

I've just pushed an update to vim-latex with a new TOC system that only parses tex files. I am tempted to update the TOC system in LaTeX-Box as well, but it is not very well tested yet. Therefore I might wait some time before I update LaTeX-Box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants