ScholarCopilot: Training Large Language Models for Academic Writing with Accurate Citations