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

Fixes #46 #99

Merged
merged 1 commit into from
Jun 25, 2020
Merged

Fixes #46 #99

merged 1 commit into from
Jun 25, 2020

Conversation

sunwukonga
Copy link
Contributor

Run tex engine before and after bib executable
Add support for both bibtex and biber

  • Add global variable g:livepreview_biber
    Add Bibliography section to README
  • Detail usage of g:livepreview_biber
  • Detail usage with biblatex

Summary

Provide a general description of the code changes in your pull request... were there any bugs you had fixed? If so,
mention them. If these bugs have open GitHub issues, be sure to tag them here as well, to keep the conversation linked
together.

Other Information

If there's anything else that's important and relevant to your pull request, mention that information here. This could
include benchmarks, or other information.

If you are updating any of the CHANGELOG files or are asked to update the CHANGELOG files by reviewers, please add the
CHANGELOG entry at the top of the relevant section.

Thanks for contributing to vim-latex-live-preview!

Copy link
Collaborator

@badouralix badouralix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sunwukonga !

Welcome and thanks a lot for your contribution 🎉
This has been a very long running problem and your solution is more than welcome !

I have added a few design comments that I think could help, let me know what you think about them

Comment on lines 187 to 227
if exists('g:livepreview_biber') && g:livepreview_biber > 0
let s:bibexec = 'biber *.bcf'
else
let s:bibexec = 'bibtex *.aux'
endif
Copy link
Collaborator

@badouralix badouralix May 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other configuration flags ( engine, previewer ) can set the binary directly, we could try to do something similar for bibliography

Suggested change
if exists('g:livepreview_biber') && g:livepreview_biber > 0
let s:bibexec = 'biber *.bcf'
else
let s:bibexec = 'bibtex *.aux'
endif
if (s:bibengine == 'biber')
let s:bibexec = 'biber ' . l:tmp_root_dir . '/*.bcf'
else
let s:bibexec = s:bibengine . ' ' . l:tmp_root_dir . '/*.aux'
endif

We should also set this in the Initialize function ( found this in https://stackoverflow.com/a/33775128, to be tested though )

    " Get the bib engine
    let s:bibengine = get(g:, 'livepreview_bibengine', 'bibtex')

" Get the tex engine
if exists('g:livepreview_engine')
let s:engine = g:livepreview_engine
else
for possible_engine in ['pdflatex', 'xelatex']
if executable(possible_engine)
let s:engine = possible_engine
break
endif
endfor
endif
" Get the previewer
if exists('g:livepreview_previewer')
let s:previewer = g:livepreview_previewer
else
for possible_previewer in ['evince', 'okular']
if executable(possible_previewer)
let s:previewer = possible_previewer
break
endif
endfor
endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went back and forth on this, but I finally settled on disagreeing with this suggested change for the following reasons:

  1. pdflatex and xelatex are drop in replacements of each other, as are evince and okular, however bibtex and biber have usages divergent enough to break things. They will be a binary choice for the foreseeable future.
  2. I don't think we should ask the user to spell something when they can simply select instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did however use get() with some added validation for both g:livepreview_engine and g:livepreview_previewer which now gives a warning if no valid executable is available for either of those roles.

\ ' && ' .
\ b:livepreview_buf_data['run_cmd'] .
\ ' && ' .
\ 'cd ' . l:tmp_root_dir . ' && ' . s:bibexec .
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should try to avoid using cd as much as possible, as this could lead some unintended behaviors and makes the code quite hard to reason about

Copy link
Contributor Author

@sunwukonga sunwukonga May 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. It's bitten me more than once on other scripts. However, I have a memory that using a path to reference the file failed for one of the bib executables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually, I wasn't able to find a way around cd like behaviour with bibtex because it doesn't allow writing to external directories without a special option set outside the purview of vim-llp.

" Update compile command with bibliography
let b:livepreview_buf_data['run_cmd'] =
\ 'env ' .
\ 'TEXMFOUTPUT=' . l:tmp_root_dir . ' ' .
\ 'TEXINPUTS=' . l:tmp_root_dir
\ . ':' . b:livepreview_buf_data['root_dir']
\ . ': ' .
\ 'bibtex ' . l:tmp_root_dir . '/*.aux' .
\ ' && ' .
\ b:livepreview_buf_data['run_cmd'] .
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inflight run_cmd is already being called once previous to this point in code, and it is called again a few lines below, do we need it here too ?

silent call system(b:livepreview_buf_data['run_cmd'])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On review, this was all kind of a mess. When I first submitted the PR, I made the simplest and easiest changes I could without upsetting the surrounding code.

After your comment, I ripped out a section of code and replaced it instead. Which cleans this up.

README.md Show resolved Hide resolved
@badouralix badouralix added the bug label May 8, 2020
@sunwukonga
Copy link
Contributor Author

I've made changes over multiple commits that reduce the clarity of the conversation to date. With your permission, I'd like to squash all the commits and --force push to clean it up. Then you'll have a clean slate to comment upon; plus the commit history will be cleaner.

Old comments only persist if they were made on the PR directly or on the files changed view; otherwise if the comment was made on a commit hash that is subsequently changed by the force, it is lost.

An alternative is for me to create a new branch and squash on it, and reference this PR in a new one. Then this PR can be rejected; but the conversation will remain intact, and a new conversation can begin on the new PR.

Copy link
Collaborator

@badouralix badouralix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah yeah yeah, feel free to do whatever you need to get a clean and clear history
I'm totally fine with force pushes, we can keep this PR
( added a few nitpicks in the meantime )

README.md Outdated
`biber`, but uses `biber` by default. To use `bibtex`, add `backend=bibtex`
to your `biblatex` usepackage declaration.

```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```
```latex

README.md Outdated
If you're using `biblatex` this is most likely caused by not also setting
`g:livepreview_use_biber = 1` in your `.vimrc`. Or if you intended to use
`bibtex` not using that option when using the `biblatex` package. i.e.
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```
```latex

let l:matches = matchstr(getline(l:position), specific_pattern)
if ( l:matches == '' )
" expect s:useBiber=1
if ( s:useBiber == 0 )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use snake case here instead of camel case, in order to keep it consistent with other variables

Run tex engine before and after bib executable
Add support for both `bibtex` and `biber`
 - Add global variable `g:latexlivepreview_use_biber`
Add Bibliography section to README
 - Detail usage of `g:latexlivepreview_use_biber`
 - Detail usage with `biblatex`
Clean up calls to bibexec commands
Remove `cd` from processing of bib commands
 - Move code that selects this option to the initializer
Give more meaningful feedback when `engine` and `preview` commands are not valid
 - Throw errors from this context
Catch errors in the initializer and then stop execution
Move README section about bibliographies
Update README to reflect change of g:latexlivepreview_biber
Add section in Known Issues about bibliographies to README
Add auto handling of certain bib setting mismatches
Fix bugged warning when `biblatex` not used
Add latex label to latex code in README
Use snake_case not camelCase
Copy link
Collaborator

@badouralix badouralix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your contribution 🎉

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

Successfully merging this pull request may close these issues.

2 participants